PHP

Microsoft’s Open Source Party in Montreal

by Joey deVilla on December 7, 2009

Here’s a little hint: if you ever get an invitation to a Microsoft party from High Road Communications – they’re Microsoft Canada’s PR firm – accept it. They’re always in great places, have great tapas and drinks and they always invite interesting people. You’re guaranteed to have fun, and that guarantee is doubled if I’m there.

The W’s “Extreme Wow” Suite

On Thursday, right after the end of Day 2 of TechDays Montreal, my fellow developer evangelist Christian Beauclair and I made our way from Centre Mont-Royal (the TechDays Montreal venue) to the W Hotel. That’s where we were holding a little party to which we invited a number of local open source developers, some of who were at the previous night’s Career Demo Camp Montreal.

w hotel montreal

Montreal’s W hotel is a building that has undergone a radical personality change. It used to be the Banque du Canada building, the home of one of our federal government’s most stuffy, buttoned-down organizations. W hotels tend to be the exact opposite: everything about them suggests that they were designed by people who usually design nightclubs, what with DJ booths in their lobbies, electronica and funk music piped into every nook and cranny, dimly-lit hallways with lighting straight out of Blade Runner and other little touches that make it seem as if you’ve somehow managed to get into one of those secret clubs in New York City’s Meat Packing District. Simply put, it’s a pretty good place to hold a swanky cocktail party,

Christian and I followed the directions to the “Extreme Wow” suite that High Road had booked for the party. Here’s what we saw when we entered the room:

01 empty suite 1

The suite was located on the top floor of the W. It was one large room with a 20 foot-high ceiling and an equally high set of windows revealing a balcony looking out onto Square Victoria and a good chunk of Montreal’s skyline. I had a sense of deja vu and soon realized that the place reminded me a little bit of Tony Prince’s swanky condo in the videogame The Ballad of Gay Tony, minus the mobsters to whom Tony owed money and wanted him dead.

02 empty suite 2

Near the back of the suite was the bathroom, which in the spirit of open source, was itself open concept and had nothing to hide. Rather than being tucked into a separate room, the shower, tub and sinks were poised on a split level four or five steps above the rest of the room, with the shower stall being a glass-and-brick enclosure in the middle of it all, looking like the monolith from 2001. The tub was recessed into the floor beside it and covered with a sheet of plywood for the party, either in order to prevent people from falling into it or to prevent me from attempting to start a party hot tub:

03 shower

(Thankfully, the toilet had its own separate “water closet” room, just off to the side.)

The room had been rearranged to better suite a party than overnight guests. The bed had been removed and replaced with a hybrid couch/chaise lounge:

04 shower and chaise

Just about everything in the room could be commanded via the master remote control, which Christian found. It controlled lights, the TV, sound system and even the curtains and skylight blinds (which could be opened and closed via remote-controlled servos):

05 christian and remote

Here’s a view of Square Victoria from the balcony:

06 view from balcony

Christian also found a table centrepiece that reminded him of an M.C. Escher image that I had used in my slide presentation at Career Demo Camp Montreal:

07a christian

For reference, here’s that M.C. Escher piece:

07b escher

Having checked out the place and taken my first set of photos, I did what I always do in such a setting: I got got a drink from the bar and made myself comfortable.

The Presentations

It wasn’t just cocktails and conversations at the party. We had some presentations as well, starting with Nik Garkusha, part of Microsoft Canada’s Open Source Strategy team. He talked about how Microsoft views open source, as well as the work we’re doing in order to make Microsoft and open source work better together.

I split his presentation into two videos. Here’s the first…

…and here’s the second:

Brendan “Digibomb” Sera-Shriar, developer with Optimal Payments, WordPress evangelist, founder of PHP Toronto and WordCamp Toronto and organizer of WordCamp Montreal, talked about his experience working with The Empire: “They’re actually doing open source!”, his use of Windows and the Windows Platform Installer and how open source and Windows can work together:

Yann Larrivee, developer, founder of PHP Quebec, FooLab and the upcoming ConFoo conference, spoke next. He talked about how he enjoyed Make Web Not War 2009, the importance of “playing well with others” both inside and outside the world of open source and how Microsoft is participating in ConFoo:

Marc Laporte, developer of TikiWiki, and among other things, talked about PHP running under IIS. It’s in French, and if anyone would like to give me a hand translating, I would appreciate it greatly!

The Party

As nice as the photos of the suite above are, the place looks far better when it’s filled with guests:

08 full suite 1

09 full suite 2

10 full suite 3

11 full suite 4

This article also appears in Canadian Developer Connection.

{ 1 comment }

oscon_language_roundtable

O’Reilly’s conference on Open Source, OSCON, takes place this week in San Jose, California. One of the events taking place at OSCON is the Open Source Language Roundtable, the abstract for which appears below:

We all have our favorite languages in our tool-belt, but is there a ‘best’ overall language? If anyone can hash that out, it will be the members of this roundtable discussion, some of the stars of the open source language space. This wide-ranging session, hosted and moderated by the O’Reilly Media editorial staff, and broadcast live on the web, will try to identify the best and worst features of each language, and which are best for various types of application development.

The roundtable will me moderated by O’Reilly Media’s James Turner and will cover the following languages, listed below with the corresponding panelist:

  • Java: Rod Johnson (SpringSource)
  • Perl: Jim Brandt (Perl Foundation)
  • PHP: Laura Thomason (Mozilla)
  • Python: Alex Martelli (Google)
  • Ruby: Brian Ford (Engine Yard)

You can catch this roundtable even if you’re not going to be at OSCON because O’Reilly is webcasting the event. It takes place this Wednesday, July 22nd at 10pm EDT (7 pm Pacific) and is expected to run 90 minutes. It costs nothing to catch the webcast and you’ll even be able to ask the panelists questions via chat, but you’ll need to register.

{ 0 comments }

“Make Web Not War” in Toronto This Wednesday!

by Joey deVilla on June 8, 2009

Make Web Not War: Toronto - Wednesday, June 10th

About Make Web Not War

If you’re interested in web design and development, you should attend Wednesday’s Make Web Not War conference. It’s being presented by Microsoft Canada and is about the how open source tools like PHP and Microsoft technologies like IIS and SQL Server 2008 can be used together to make great web sites and applications. No matter how much (or how little) Microsoft technology you use in your web development, there’s a lot to see at Make Web Not War!

Who’s Speaking?

We’ve got a number of speakers, each talking about some different aspect of the interoperability between Microsoft and open source technologies, as well as their experiences and lessons learned working in the web industry:

David Crow

David Crow, Microsoft

David Crow is an emerging technology and start-up advocate. At Microsoft Canada, he is responsible for helping Canadian start-ups through programs like BizSpark (details at microsoft.com/bizspark). David helps companies understand emerging technology and design practices for creating compelling digital experiences. David focuses on helping companies to extend their customers’ reach with next generation technology for the desktop, digital devices, standards based applications for the Web, and rich media applications. He has been named Toronto’s Best Web and Tech Evangelist for his efforts in DemoCamp, BarCampToronto, Founders & Funders and StartupEmpire.

Mano Kulasingam

Mano Kulasingam, Digiflare

Mano Kulasingam is a founding partner and principal interactive designer /developer with Digiflare, focusing on presentation layer technologies like Microsoft Silverlight, Windows Presentation Foundation and SharePoint 2007. He also has several years of experience developing B2B and B2C eCommerce and Content Management Web applications using ASP.NET (2.0 and 3.5) and Visual C#. His design skills include working with the latest professional design tools including Microsoft Expression Studio 2, which has earned him a Microsoft Expression MVP nod. He is a co-founder and host of the Toronto Silverlight User Group.

Brendan Sera-Shriar

Brendan Sera-Shriar, PHUG.ca

Brendan is a prominent member of FlashinTO, PHUG – Open Source Culture, has taught web design at Long Island University Brooklyn campus, and has been a professor at Seneca College in the School of Communication Arts for over 7 years. Brendan currently owns and operates BackSpaceStudios, a web company specializing in WordPress development, social media applications. He is also the founder of PHUG, an open source community for designers and developers with currently over 4000 members, faculty at Seneca College, and organizer for WordCamp Toronto 2009. Brendan has contributed to many open source projects including papervision3D, red5, Firefox, WordPress, and Drupal, just to name a few.

Stephen Nichols

Stephen Nichols, Softcom

Under the brand myhosting.com we offer Shared and Virtual Web Hosting as well as Exchange 2007 and WSS hosting to customers around the world.

Stephen is Vice President of Sales at Softcom, a Gold certified Microsoft Partner based in Toronto and specializing in transactional hosting with a focus on the SMB market. His key role is to oversee the customer life cycle experience and drive new sales opportunities through the direct, affiliate and partner channels.

Yann Larivee

Yann Larivee, PHP Quebec

Yann Larrivée has been developing web applications for over 7 years and is currently offering PHP consulting services. In the past he has worked in many position from, project manager for a Linux consulting company to web architect for a well know company in the gaming industry. He also founded the PHP Quebec community in 2003 and organizes an international PHP conferences and an IT JobFair.

Get Windows Server 2008 R2 for Free!

Windows Server 2008 R2 logo

Windows Server 2008 R2 is a great server operating system, and this is your chance to take it out for a spin! Bring a machine to the Make Web Not War Installfest – it could be a server, desktop or even a laptop – and we’ll walk you through the process of installing your own free copy (which is good for a year). Space is limited – we’ve only got room for 100 people, so sign up soon!

See the Utltimate FTW! Throwdown

The Ultimate FTW! Throwdown was a challenge pitting student developers against professionals to develop a new PHP-on-Windows app or port an existing PHP-on-LAMP app to run on Windows Server with IIS. There were even bonus points for apps that made use of SQL Server as their database!

We took in a bunch of submissions, and the judges have narrowed it down to two finalists, one student, one professional:

Dac Chartrand In the professional corner is Dac Chartrand, whose submission is Sux0r, a content-management system incorporating blogging, RSS aggregation, bookmark repository and photo publishing, all with a focus on naive Bayesian categorization and probabilistic content. The extra Bayesian/probabilistic goodies allow Sux0r to auto-categorize its content and users to train it to categorize better.

Casron Lam His student opponent, Carson Lam, submitted Transit DB, which aims to transform the way commuters interact with public transit information system. The application is Carson’s answer to the question “How can we provide a modern, clean and user-friendly interface for transit data in cities?” The current version covers public transit for the Metro Vancouver region.

Dac and Carson will be competing for bragging rights and cold hard cash – may the best project win!

(For more details about the Ultimate FTW! Throwdown, see its page on PHPonWindows.ca.)

Interact

Telav audience device

We don’t want to do all the talking at Make Web Not War, we also want to hear from you!

That’s why, when you arrive at the event, one of the first things we’ll do is hand you an AVW-TELAV audience response doohickey. It’s a microphone for the Q&A sessions at the end of each presentation, but it’s also an instant audience polling device for quick surveys that we’ll have throughout the day.

Chill Out

All work and no play makes you a dull and burned-out web designer or developer, which is why we’ve also got a lounge where you can just hang out, meet the speakers, ask me questions about Microsoft’s web tools and tech and play XBox games.

Win prizes

We’ve got all sorts of prizes that you can win throughout the day, from software to books to trainign courses to Zune media players to XBox games to a brand new laptop.

Get Fed

Yup, we’re providing breakfast and lunch. You can’t conference on an empty stomach!

Okay, How Much to Attend?

Around this much:

Canadian $10 bill

Instead of charging a standard admission, we’re charging a “Donate what you can” rate, with all proceeds going to PREVNet.ca, an anti-bullying group. The suggested donation is a mere $10.

When and Where?

Once again, Make Web Not War takes place this Wednesday, June 10th and runs from 8:30 a.m. to 5:00 p.m..  It’s happening in Toronto at Ryerson University’s Ted Rogers School of Management (55 Dundas Street West – that’s Dundas between Bay and Yonge, right by the Best Buy and Canadian Tire). There’s parking aplenty in the area, and it’s right by Dundas Station on the Yonge/University/Spadina subway line.

Map picture

 

How Do I Register?

Visit the Make Web Not War registration page and fill out your details, and we’ll see you there on Wednesday!

{ 4 comments }

PHP on Windows: The Undiscovered Country

by Joey deVilla on May 12, 2009

This article also appears in Canadian Developer Connection.

I’m doing a lot of running around today. First, I’m off to the University of Waterloo to talk to students about PHP on Windows and the PHP FTW! contest. Then, it’s back to Toronto, where I’m headed downtown to catch up with Garrett Serack from Microsoft’s Open Source Software Lab to talk about The Empire, Open Source (which includes PHP, of course) and how they fit together. If this sounds like a conversation you’d be interested in joining, drop me a line!

To give you a taste of what Microsoft is doing with PHP, I present the slides from Garrett’s talk, PHP on Windows: The Undiscovered Country, which he gave last year. Things have advanced since then, but I thought it would give you an idea of what The Empire is thinking and where we’re going with PHP on the Windows platform:

{ 0 comments }

Got Time Tuesday After Work?

by Joey deVilla on May 11, 2009

PHP logo

If…

  • you’re a PHP developer or curious about what Microsoft is doing in the world of open source
  • you’re in the downtown Toronto area tomorrow (Tuesday, May 12th) after work
  • you like free food and drink

…then drop me a line. I’m helping out at an event that you might be interested in.

{ 0 comments }

This article also appears in Canadian Developer Connection.

Coffee cup

This week, I’m going to have my hands full on Friday with WordCamp Toronto, so I’m moving my Coffee and Code session from Friday to this Thursday, May 7th, from 2:00 p.m. to 5:00 p.m. at the Dark Horse Cafe (215 Spadina).

This particular Coffee and Code has a theme: developing and deploying PHP applications on Windows. I’ll be talking about and answering questions about PHP on Windows, the Web Platform Installer (which I recently covered in this article) and the PHP FTW! contest, which pits student developers against professional developers for cash prizes.

Come on down and join me for a coffee! I’m going to see if I can bring some PHP-themed goodies to give away, just in case my scintillating company and Dark Horse’s great coffee aren’t enticements enough for you to drop by.

{ 0 comments }

This article also appears in Canadian Developer Connection.

Yesterday, I showed you how to install MySQL Server 5.1 (Community Edition) onto your Windows-based development machine. The reason I wrote the article was to help you prep your machine for installing PHP and PHP-based applications using Microsoft’s Web Platform Installer.

What is Web Platform Installer?

Web Platform Installer is, as the website puts it, “a free tool that makes it simple to download, install and keep up-to-date with the latest components of the Microsoft Web Platform”. Yes, this is stuff you can do yourself, but I’m all for tools that automate away drudgery.

As of this writing, there are two versions of Web Platform Installer available: the original 1.0 version and the beta 2.0 version. In this article, I’m going to focus on the 2.0 version.

Here’s what you’ll see when you fire up the Web Platform Installer 2.0 beta:

wpi_01

Web Platform Installer has three tabs:

  1. What’s New?: This lists the newest applications that are available for download and aren’t already installed on your system. This is the tab that is automatically selected when you launch Web Platform Installer.
  2. Web Platform: This lists web platform applications that are available for download and whether they’re installed on your system. These apps are divided into the following categories:
    • Web Server Applications: Extensions for IIS as well as other server software such as the FTP server
    • Frameworks and Runtimes: Both Microsoft and open source frameworks and runtimes, such as .NET Framework and ASP.NET MVC. This is where you’ll find PHP.
    • Database: SQL Server Express and management tools.
    • Tools: Applications for web development, such as Silverlight and Visual Web Developer Express.
  3. Web Applications: This lists web applications that are available for download and whether they’re installed on your system. These apps are divided into the following categories:
    • Blogs: A selection of .NET blogging apps such as BlogEngine.NET and DasBlog, as well as WordPress.
    • Content Management: Applications like DotNetNuke and Acquia Drupal.
    • Galleries: Photo gallery applications.
    • Wiki: Wikis and apps with wiki functionality, such as the PHP-based Acquia Drupal and the ASP.NET-based ScrewTurn Wiki.

Installing PHP

If PHP isn’t on your system, it will appear on the What’s New? tab page. If you click on the “information” icon beside the checkbox item for PHP, you’ll be shown its information page:

wpi_02

You can choose to install PHP by checking PHP’s checkbox in the list of applications or the Click to include in your install button.

You can choose to add other applications to your install. Once you’ve chosen all the apps you want, click the Install button. You’ll be presented with a list of the apps you chose for review, along with any dependencies for those apps:

wpi_04

To start the installation, click the I Accept button, and Web Platform Installer will do its thing:

wpi_05

Taking PHP for a Quick Spin

Let’s write a very quick script to confirm that PHP is up and running:

<?php

phpinfo();

?>

In case you’re not familiar with PHP’s built-in phpinfo() function, it returns information about your PHP installation, its configuration and its current environment. It’s useful for all sorts of things, not the least of which is checking to see if your PHP installation worked.

Enter the script above using your favourite editor, and save it as test.php into the web root directory, c:/inetpub/wwwroot Note that in order to save to this directory, you’ll need to be running the editor with administrator privileges. Alternately, you can save to another directory and then copy the file to c:/inetpub/wwwroot, giving your administrative approval when prompted by the dialog box.

Then point your browser at http://localhost/test.php — you should see something that looks like this:

wpi_06

Next Steps

With PHP up and running, you can install PHP-based apps. PHP apps are like old-school ASP apps; installing them is often a matter of moving the files into the webroot directory and perhaps running an install script by typing its URL into your browser.

phpMyAdmin

One app you might want to consider installing is phpMyAdmin, a PHP-based web application for administering MySQL databases. While it’s possible to administer MySQL solely through its command-line interfaces, phpMyAdmin makes it so much easier. I can’t recommend this utility enough.

Cover of "Wicked Cool PHP"

If I had to recommend just one PHP book, it would be No Starch Press’ Wicked Cool PHP. I find No Starch books to be both informative and enjoyable reads, and this book is no exception. If you’ve got at least a little programming experience under your belt. I think that you’ll find this book and its very useful examples, coupled with the online documentation at PHP.net, will serve you very well.

Happy PHPing!

{ 0 comments }

The “FTW!” Ultimate PHP App Throwdown

by Joey deVilla on April 19, 2009

For the Win! For the Web! FTW: Ultimate App Throwdown -- Professionals vs. Students

This article also appears in Canadian Developer Connection.

Wait a Minute…Microsoft and PHP?

You probably wouldn’t be surprised that Microsoft is holding a development contest that pits professional developers against student developers. You might be surprised that Microsoft is holding a development contest where the challenge is to build a PHP application.

You read that right: PHP. Microsoft’s web server, IIS (Internet Information Services) can run PHP as well as ASP.NET; in fact, it can even run both on the same site at the same time, so you can have apps like WordPress along with your ASP.NET-based apps.

Think of ASP.NET and PHP running on the same server as the great jam session with Spock and the space hippie from that old Star Trek “hippies in space” episode.

Spock and a space hippie, jamming on their instrumentsSee? We’re not Herbert!

Even more unexpected is that the beta for the 2.0 version of the Microsoft Web Platform Installer doesn’t do a “couple-of-clicks” installation of the expected stuff like IIS and SQL Server 2008 Express, it also provides a “couple-of-clicks” installation of PHP and WordPress.

The FTW! Throwdown

"Goopymart" comic of a dog holding a trophy: "FTW!"

That’s “FTW!” as in “For the Win” or “For the Web”, by the way.

The contest is pretty simple: the idea is to show the best application written in PHP and deployed on Windows. The app can be either:

  • A new application developed by you in PHP and running on IIS in Windows
  • An existing application or framework written in PHP and ported by you to run on IIS in Windows

That’s right: if you’re pressed for ideas or time to make a new application, it’s all right – you can take a PHP application that already exists, make the necessary changes so that it’ll run on IIS (and hey, for bonus points, make it tie into SQL Server instead of MySQL), and submit that as your contest entry!

Students vs. Professionals

Another twist to the FTW! Throwdown is that we’re getting student developers and professional developers to challenge each other. The pros have experience and resources on their side; students have youthful energy and fewer distractions going for them. Not since “Pirates vs. Ninjas” has there been a challenge like this!

One application developed or ported by students and one application developed or ported by professionals will be chosen from the submissions for the Ultimate Challenge, which will be a final bout at Microsoft’s Make Web, Not War conference. In that last match, it “Two apps enter! One app leaves!”. Simply put, one of the apps – either the student one or the professional one – will be declared the Ultimate Champion.

As they said in Highlander: “There can be…only one!”

The Booty

Stuffed animal prizes at a carnival

We want to reward the best contestants for their efforts in the FTW! Throwdown, and we plan to do so with some pretty nice prizes, which include:

  • The grand prize: $5000 for the winning entrant.
  • The runner-up prize: $3000 for the runner-up.
  • The SQL Server prize: $3000 for the finalist whose app showcases the best use of PHP with a Microsoft SQL Server database.
  • The PHP/.NET Mash-Up prize: $2000 for the finalist whose app showcases the best of PHP with .NET-based code working together in a single application.
  • The student finalist prize: The student developer who makes it to the last match will also get an interview and resume critique from Microsoft and a $200 Petro-Canada gas card.
  • The professional finalist prize: The professional developer who makes it to the last match will also get a chance for a published case study, enrollment in the MAPS or EMPOWER program and a $200 Petro-Canada gas card.

Hosting Options

Naturally, the apps that you submit for the FTW! Throwdown need a place to live. If you don’t already have IIS hosting, our partners at myhosting and RackForce are offering a 60-day free hosting promotion.

Deadlines and Details

The deadline for entering the FTW! Throwdown is Wednesday, June 3rd, 2009. Finalists will be announced on Friday, June 5th, 2009, and the main event where the student finalist faces off against the professional finalist happens on Wednesday June 10th, 2009.

If you’d like to know more about the FTW! Throwdown, visit the FTW! Throwdown site. I’ll be posting regular bulletins about the FTW! Throwdown on this blog, and you can follow the FTW! team on Twitter as the user @PHPOnWindows and the hashtag #FTW09.

{ 0 comments }

Using the Twitter API with PHP and PEAR

by Joey deVilla on April 15, 2009

PHP, PEAR and Twitter logos

The Zend Developer Zone article Using the Twitter API with PHP and PEAR covers the Services_Twitter PEAR package, which the articles describes as follows:

Services_Twitter works by providing a full-fledged, object-oriented interface to the Twitter API. This interface insulates you from the nitty-gritty of working directly with REST requests and, by representing responses as SimpleXML objects, makes it very easy to access specific elements of the returned data. This not only saves time; it’s also simpler, because it’s no longer necessary to be intimately aware of the nitty-gritties of the Twitter API in order to use it effectively.

{ 0 comments }

My Tech Reading List for May

by Joey deVilla on May 1, 2008

I got a number of books for free this past week:

Books I\'m reviewing in May 2008

  • Head First PMP – When my friend Leigh Honeywell heard that I was taking a project management course later this month, she told me that she got this book for free at a conference and had no use for it. So she gave this book to me, and I’ll be reading it so that when the course comes around — it’s May 21st through 23rd — I’ll be at least familiar with the material.

And four books from Apress, courtesy of Julie Miller:

I’ll be reading them this month and posting my reviews here in Global Nerdy. Watch this space!

{ 0 comments }

In PHP, There’s Equality, and Then There’s EQUALITY

by Joey deVilla on December 12, 2007

Ka=Ping Yee’s Equality Test

Here’s a quickie PHP script based on the one that appears in Ka-Ping Yee’s LiveJournal entry titled Why PHP Should Never Be Taught:

<?php
$a = 0;
$b = "eggs";
$c = "spam";
$e = "eggs";

echo "<h1>The \"==\" Exercise</h1>";
echo "<ul>";
echo "<li>\$a is $a</li>";
echo "<li>\$b is $b</li>";
echo "<li>\$c is $c</li>";
echo "<li>\$d is undefined</li>";
echo "<li>\$e is $e</li>";
echo "</ul>";

echo ($a == $b) ? "\$a == \$b<br />" : "\$a != \$b<br />";
echo ($b == $c) ? "\$b == \$c<br />" : "\$b != \$c<br />";
echo ($a == $c) ? "\$a == \$c<br />" : "\$a != \$c<br />";
echo ($a == $d) ? "\$a == \$d<br />" : "\$a != \$d<br />";
echo ($b == $d) ? "\$b == \$d<br />" : "\$b != \$d<br />";
echo ($c == $d) ? "\$c == \$d<br />" : "\$c != \$d<br />";
echo ($b == $e) ? "\$b == \$e<br />" : "\$b != \$e<br />";
?>

If you’re not familiar with PHP’s quirks, you’ll find the output surprising:

The “==” Exercise

  • $a is 0
  • $b is eggs
  • $c is spam
  • $d is undefined
  • $e is eggs

$a == $b
$b != $c
$a == $c
$a == $d
$b != $d
$c != $d
$b == $e

What Happened?

In PHP, as with many other programming languages, the == operator is the equality operator, which returns true if the operands on either side are equal in value. It works as expected when used on operands of the same type, as evidenced by the program above, which states that $b is equal in value to $e, both of which are set to the string eggs.

We get into strange territory when the == operator is used to compare operands of different types. The program above evaluates the boolean $a == $b as true even though $a is set to the integer value 0 and $b is set to the value eggs. How can eggs be equivalent to 0? They’re so tasty and versatile! Damned anti-ovites!

In PHP, the == operator is what I like to call the “Slack Equality Operator”. When used to compare a string and a number, it attempts to convert the string to a numeric type and then performs the comparison. The following example code, taken from the PHP documentation, shows how PHP’s string-to-number coercion works:

<?php
$foo = 1 + "10.5";                // $foo is float (11.5)
$foo = 1 + "-1.3e3";              // $foo is float (-1299)
$foo = 1 + "bob-1.3e3";           // $foo is integer (1)
$foo = 1 + "bob3";                // $foo is integer (1)
$foo = 1 + "10 Small Pigs";       // $foo is integer (11)
$foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2)
$foo = "10.0 pigs " + 1;          // $foo is float (11)
$foo = "10.0 pigs " + 1.0;        // $foo is float (11)
?>

Hence the eggs/zero equivalence: the string eggs is coerced to 0.

Enter the === Operator

I like to call the === the “Strict Equality Operator”. It returns true if and only if:

  • Both operands are the same type
  • Both operands have the same value

Here’s the code I showed at the start of the article, but with all instances of == replaced with ===:

<?php
$a = 0;
$b = "eggs";
$c = "spam";
$e = "eggs";

echo "<h1>The \"===\" Exercise</h1>";
echo "<ul>";
echo "<li>\$a is $a</li>";
echo "<li>\$b is $b</li>";
echo "<li>\$c is $c</li>";
echo "<li>\$d is undefined</li>";
echo "<li>\$e is $e</li>";
echo "</ul>";

echo ($a === $b) ? "\$a === \$b<br />" : "\$a != \$b<br />";
echo ($b === $c) ? "\$b === \$c<br />" : "\$b != \$c<br />";
echo ($a === $c) ? "\$a === \$c<br />" : "\$a != \$c<br />";
echo ($a === $d) ? "\$a === \$d<br />" : "\$a != \$d<br />";
echo ($b === $d) ? "\$b === \$d<br />" : "\$b != \$d<br />";
echo ($c === $d) ? "\$c === \$d<br />" : "\$c != \$d<br />";
echo ($b === $e) ? "\$b === \$e<br />" : "\$b != \$e<br />";
?>

Here’s the output, which behaves as expected:

The “===” Exercise

  • $a is 0
  • $b is eggs
  • $c is spam
  • $d is undefined
  • $e is eggs

$a != $b
$b != $c
$a != $c
$a != $d
$b != $d
$c != $d
$b === $e

Once More, in Ruby

Just for kicks, I thought I’d translate the original code into Ruby just to see what would happen. Here’s the code:

a = 0
b = "eggs"
c = "spam"
e = "eggs"

puts "a is 0"
puts "b is 'eggs'"
puts "c is 'spam'"
puts "e is 'eggs'"

puts a == b ? "a == b" : "a != b"
puts b == c ? "b == c" : "b != c"
puts a == c ? "a == c" : "a != c"
puts a == d ? "a == d" : "a != d"
puts b == d ? "b == d" : "b != d"
puts c == d ? "c == d" : "c != d"
puts b == e ? "b == e" : "b != e"

…and here’s the output:

a is 0
b is 'eggs'
c is 'spam'
e is 'eggs'
a != b
b != c
a != c
double-equals.rb:14: undefined local variable or method `d' for main:Object (NameError)

Links

{ 1 comment }

Tim “Ongoing” Bray’s Take

Tim Bray posted a blog entry on what drives adoption of a language in which he included some tables such as the only below:

Flawed
Founders
Polished
Successors
Procedural FORTRAN, COBOL, PL/1 C
Object-Oriented C++ Java
Higher-Level Perl, TCL Python, Ruby

This table of his should inspire a monkey knife fight on a number of blogs:

Flawed
Founders
Polished
Successors
Web-Centric WebObjects, ColdFusion, ASP.Net, Struts, etc.,
etc., etc., PHP
Rails

Here’s an interesting one. What will JavaScript’s successor be? My guess for the short-term (by that, I mean “the next half-dozen or so years”) is “the next version of JavaScript”.

Flawed
Founders
Polished
Successors
Mobile-Code JavaScript ?

The one about concurrent programming is a little more up in the air. Although there are other languages designed with concurrent programming in mind (either from the ground up or with concurrency retrofitted onto an existing language) and there have been for a while (I used Concurrent C in a course back at Crazy Go Nuts University in the early ’90s), Erlang is getting a lot of the attention these days since it has both a success story at Ericsson under its belt as well the clout of a Pragmatic Programmers book behind it. There is a feeling among some programmers (Bray included) that it isn’t going to be the language to turn concurrent programming from arcane art into mainstream practice:

Flawed
Founders
Polished
Successors
Concurrent Erlang ?

Shelley “BurningBird” Powers’ Take

Shelley Powers disagreed with Tim’s assessments in her posts Flaws are in the Eye of the Beholder:

I find it fascinating when a person marks as ‘flawed’ the languages that have, literally, defined not only the web but application development of all forms. Perhaps the metric shouldn’t be on syntax, form, or function, but on usability.

Here’s her own table on languages:

'Perfect', but barely used 'Flawed', but simple, approachable, powerful, popular
Higher-Level *Ruby (every time I see 'Ruby' I mentally add, Mama's precious little…)

*I’m giving Python a slide because Python has fairly widespread use today.

Perl
Client side code (The to-be-created scripting language that will take a nice, clean, easy to use language and morph it until it satisfies the purists, while breaking faith with the millions of users just trying to do a job) JavaScript
Object Oriented Java (bloated beyond recognition with senseless additions and overly complex infrastructures) C++ (which can kick Java's ass performance and resource wise)
Web-Centric Rails (you know that thing they used for the one application?) Cold Fusion, ASP and ASP.NET, PHP

Those of you who recall Bjarne “C++” Stroustrup’s line “There are just two kinds of languages: the ones everybody complains about and the ones nobody uses” or the essay Worse is Better (or the essay that led to it or Jamie Zawinski’s commentary on it) should be feeling deja vu now.

As for Shelley’s table, I’d probably have put “PHP” where “Perl” is right now.

My Own Take

I think that right now, the “scripting languages” are stuck in something akin to “Three Stooges Syndrome”. That’s the disease where Mr. Burns from The Simpsons, being so old and frail, has so many diseases trying to get at him at the same time that they’re all “stuck in the door”. The doctors illustrated the syndrome with a model, shown below:

“Three stooges syndrome” from “The Simpsons”: All the germs and viruses are stuck in the door because they tried to get in all at once.

And since Tim and Shelley have their tables, I thought I’d make one too:

Scripting Stooge What’s Driving It
Perl Legacy: it was the original “duct tape of the internet”.
PHP Widespread adoption, drives a lot of apps, easy to program, easy to deploy.
Python Very readable, one of the 4 languages approved for use at Google (the others being C++, Java and JavaScript, according to Steve Yegge).
Ruby Ruby on Rails, which is a very nice framework from the web app developer’s point of view. That and maybe the fact that DHH is rather photogenic (although PHPer-turned-Pythoner Leah Culver could give him some competition).


Cross-posted to the Tucows Developer Blog.

{ 0 comments }

Sign Up for PHP Training, Get an iPod touch (or Two!)

by Joey deVilla on September 21, 2007

iPod Touch displaying the PHP logoHere’s a sweet deal from php | architect magazine, to which I am a subscriber: sign up for online PHP training before the end of November and they’ll give you an iPod Touch…or maybe two! Click here for details about this offer.

Cross-posted to the Tucows Developer Blog.

{ 0 comments }

Facebook Development: Photos, Part 3

by Joey deVilla on August 31, 2007

Facebook Polaroid Camera 3

The Facebook development articles continue at the Tucows Developer Blog, this time with Using the FacebookRestClient Class’ “Photo” Methods, Part 3: photos_getTags.

{ 1 comment }

Facebook Development: Photos, Part 2

by Joey deVilla on August 24, 2007

Facebook Polaroid Cameras

More Facebook application development goodness at the Tucows Developer Blog: Using the FacebookRestClient Class’ “Photo” Methods, Part 2: photos_get.

{ 0 comments }