Archive for December, 2006
Sat, 23 Dec 2006 3:43 UTC
It’s become a personal tradition of mine to try various winter and holiday ales and lagers each year around this time. I’ve also found that many members of the PHP community are aficionados of good beer. Thus, my Christmas gift to the PHP community this year will be a list of recommended winter brews. I won’t spend too much time describing the beers. Instead, I’ll link to their pages at Beer Advocate (a PHP-driven site) for reviews.
- Sweetwater Festive Ale 2006, Sweetwater Brewing Company
You can tell I’m a big fan of the Samuel Adams beers. My favorites in this list are the Sierra Nevada Celebration Ale and the Samuel Adams Winter Lager (always a winter favorite of mine). I was somewhat disappointed with the 2006 recipe for the Sweetwater Festive Ale; it was a bit too sweet for my liking, but I list it here because it’s an Atlanta beer.
Feel free to leave a comment with your winter brew recommendations.
Cheers and Merry Christmas!
5 Comments »
Permalink
Tags: ale, beer, christmas, community, holiday, lager, php, winter
Thu, 21 Dec 2006 14:36 UTC
In my effort to clean my plate of blog topics, here’s yet another post for this week. I promise to keep this one much shorter . . .
When discussing RESTful Web Services, I’ve often been known to say that I find it difficult to envision how POST fits in with the REST model. This is because my thinking has been stuck in the past with the old way of doing things. For example, consider the following form that uses the POST method:
<form method="POST" action="create-customer.php">
Name: <input type="text" name="name" /><br />
Address: <input type="text" name="address" /><br />
E-mail: <input type="text" name="email" /><br />
<input type="submit" />
</form>
This form is simple enough. When the user submits it, they send a POST request to create-customer.php to create a new customer in the system with the given name, address, and email values. The problem here is that create-customer.php does not follow the REST model. It does not uniquely identify a resource. Instead, it merely processes data. If I were to call it with a GET request, what would it return? Maybe nothing. This is the RESTless way of doing things.
The RESTful approach requires that all URIs uniquely address a particular resource. With this in mind, an attendee at a recent Atlanta PHP meeting pointed out that the creation of a new customer could be as simple as changing the POST action to /customer. Again, the light bulb in my brain still did not light up because I was thinking about the “old way.”
I suggested that /customer, while it accepts POST data, would still return perhaps the newly created ID of the customer after creation, and this does not represent a unique resource. He pointed out that, when POSTing, you don’t have to get back a unique resource, but if you were to GET it, you should. Thus, when you GET /customer, the response might include an XML document listing all the customers. However, POSTing to it, might create a new customer that gets “inserted” into that listing. Likewise, GETing /customer/1138 returns an XML document of customer data for the customer with ID 1138, but POSTing to it would update the data for that customer.
That’s when the light bulb clicked on, and I realized that it is, in fact, possible to design a RESTful application that makes use of GET, POST, PUT, and DELETE in a very RESTful way.
4 Comments »
Permalink
Tags:
Wed, 20 Dec 2006 20:16 UTC
From the I-noticed-this-one-day-while-looking-at-a-co-worker’s-code department comes a tale about the use of undefined constants in PHP—and relying on this twisted “feature” to make an application function properly.
So, there I was, looking over the shoulder of a colleague, trying to help him debug an application, when I saw something that struck me as quite odd.
“Where is that constant defined?” I asked, pointing to the screen.
“What constant?”
It was plain as day to me. “That constant.”
“Oh, that’s not a constant. It’s a string.”
“No, it’s not,” I retorted. “If it’s a string, why are there no quotation marks. You should be getting an error about an undefined constant.”
“No, it’s a feature of PHP. You don’t have to use the quotation marks.”
And then it struck me: If this is a feature, it’s most likely the dumbest feature I’ve ever seen. Perhaps Jamie of Yet Another Web Development Blog has something there . . .
Nevertheless, after digging around some, I found this in the PHP manual:
If you use an undefined constant, PHP assumes that you mean the name of the constant itself, just as if you called it as a string (CONSTANT vs “CONSTANT”). An error of level E_NOTICE will be issued when this happens. See also the manual entry on why $foo[bar] is wrong (unless you first define() bar as a constant).
PHP: Constants
Hmm. So, if $foo[bar] is wrong, remind me again why this is even a feature? In my opinion, it should return, at the least, an E_WARNING error. Instead, the error level is E_NOTICE, but let’s examine what happens when the millions of people running distribution versions of PHP use this “feature.”
Most distributions use the php.ini-dist file instead of the php.ini-recommended file. This means that error_reporting is set to E_ALL & ~E_NOTICE and notices are not generated or displayed, so users will never know about their undefined constants. My colleague was using the PHP distribution for Debian, Debian’s default php.ini settings, and, thus, was never aware of the notices generated by the use of undefined constants. What’s worse is that the code my colleague was using was not his own—it was third-party, open source software!
Here’s why it’s bad to rely on this behavior. In the follow snippet of code, I expect that foo will always be the string “foo.” The problem is that I’m really using an undefined constant.
<?php
$var = foo;
my_func($var);
?>
When I pass $var to my_func(), the function may do something that expects the value to be the string “foo,” but what if the core developers decide to add a constant with the name foo and assign it a value. Now, $var is no longer the string “foo.” It’s whatever the language has defined it to be. That’s an unlikely scenario, but what if another programmer in my team decides to define the constant foo (this is much more likely)? Now, the code mysteriously breaks, and it’s difficult to find the problem (especially because E_NOTICE is turned off). Even worse: what if I’m using third-party code that relies on this behavior, and I’ve integrated it into my application that has some global constants by the same names set?!
So, the lessons learned from this are:
- Always develop applications using an error level of
E_ALL or E_STRICT; when you encounter notices, fix them because they could indicate problems with your logic that may not immediately present themselves
- If you want a string value, use quotation marks (single or double), otherwise, treat your “string” as a constant because that’s what it is
- Don’t rely on the use of undefined constants—they aren’t
NULL or empty; instead, they are actually the string value of the constant name
Note that this behavior of constants continues to exist even in the latest versions of PHP, including 5.2 and 6.0.0-dev. Why? I don’t know.
9 Comments »
Permalink
Tags: constants, errors, php, strings, undefined
Tue, 19 Dec 2006 15:09 UTC
This post is long overdue, but I was finally able to sit down and type out my thoughts about the Zend/PHP Conference and Expo and the International PHP Conference. I had the privilege of being invited to speak at both of these conferences, and I accepted both invitations, which, in retrospect, may not have been a great idea since they were back-to-back in different parts of the world; I felt like I knew the NSA on a first-name basis. Looking back, though, I enjoyed each trip because I was able to meet new people, develop new friendships, and spend time with old friends.
Zend/PHP Conference Wrap-up
The Zend Conference started out great, ushering in a new era of the community-made t-shirt, and the week was awesome up until the moment immediately following my presentation. The week started with a visit to a couple of wineries for tastings, courtesy of Andrei (our chauffeur). We also had some great dinners, and I was able to catch up with a few friends and meet some people I have only spoken with via e-mail. The day of tutorials was excellent; I sat in on Rob Richards’s “Advanced XML and Web Services” and Marcus’s and Sara’s “Extending PHP” tutorials. Both were very informative, though I would’ve liked to have seen more practical examples of Web Services, and I wish my attempt to connect to Sara’s ad hoc network hadn’t hosed my wifi connection (it took a full day to connect to any other wifi network and pick up an IP address). It is important to mention, though, that the ZendCon wifi was outstanding (compared to other conferences).
Then, the disaster came that ruined my enjoyment of the entire week.
On Tuesday afternoon, immediately following Chris Anderson’s keynote presentation, I gave my “XML & Web Services with PHP” presentation. While setting things up for the presentation, I removed my laptop and power cables from my bag, and then placed my bag on the ground—I thought it was at my feet. After my presentation, however, my bag was missing, along with my camera, iPod, spare laptop battery, folders of work and writing notes, and more. Luckily, I had my laptop, but I was nevertheless livid. After a thorough search of the area, checking with hotel and conference staff, and posting a “lost bag” notice, I still hadn’t found it. And it never turned up during the entire week. It was all I could think about. I couldn’t focus on any of the presentations, and I wrote it off as having been stolen, which made me even more angry that someone would steal my bag right out from under me and that this bastard was a member of the PHP community.
On the Saturday following the conference, Chris Anderson—yes the keynote presenter and editor-in-chief of Wired Magazine—contacted me saying that he was in possession of my bag. From what I can gather, it seems that when they were closing the walls of the main conference room to divide it into the three session rooms, they closed my bag on the other side of the wall from the room in which I gave my presentation. Since the bag was near the stage of the middle room, someone assumed it belonged to Chris Anderson who had just given his keynote presentation from that stage. What happened next is left to interpretation. Chris told me that the “gift bag they handed [him] at the Zend conf registration” appeared to be the bag I had lost. There are two things that could have happened: 1) someone turned in the bag, claiming it was Chris Anderson’s, and he assumed it was his “gift bag” when they returned it to him, or 2) the conference organizers had Nike bags similar to mine to give to the keynote presenters, and when they found my bag, they assumed it was one of their gift bags, so they took it back to the registration tables and gave it to Chris. In either case, he somehow ended up with my bag as his keynote gift.
At any rate, Chris quickly returned my bag, and my faith in humanity and the PHP community was restored. Still, the conference was a bit ruined for me, but that doesn’t say anything about the topics, speakers, or Zend. The last night of the conference was great, though, complete with an IBM pirate-themed party and Microsoft-sponsored drinks and karaoke. There are pictures floating around on Flickr.
International PHP Conference Wrap-up
The last time I spoke at the International PHP Conference was during the Spring Edition 2005 in Amsterdam. The location in Amsterdam was ideal. It was right next to a train station, and a tram stop was only a couple of blocks away, giving conference goers easy access to the entire city. The conference location in Frankfurt, while undoubtedly cheaper than Amsterdam (you can’t beat €87 a night!), was farther out from the city with no nearby train stations (the closest was several kilometers away). While I was able to explore Amsterdam everyday during my stay, I managed to leave the Frankfurt hotel only one night.

My complaints, however, deal primarily with the location. The conference, on the other hand, was excellent, as usual. The organizers, S&S, always put on a polished and well-presented conference, complete with excellent conference materials, right down to the programs, badges, and hoodies given to speakers. The European atmosphere feels familiar with noticeable differences—chances are, if an attendee has a Mac, they’re from the US, while the Europeans tend to have IBM hardware. Also, what is the German obsession with sparkling water and small glasses? Perhaps it’s my gluttonous Americanism, but I love to drink lots of water (without bubbles). Nevertheless, it’s not hard to get used to, and, since I’ve returned, I’ve found myself craving a glass of sparkling mineral water on occasion.
While at the IPC and in-between trying to fulfill work commitments, I managed to make it to Aaron Wormus’s workshop on “Mastering enterprise-level PHP tools PEAR, PhpDocumentor and testing,” Marcus’s “The Need for Speed, ERM Testing,” and Sara’s “Navigating Streams.” Two great highlights of the conference were the PHP-Lounge and Code Camp (led by Marcus and Sara). I didn’t make it to the Code Camp, but I’ve heard good things about it, and the PHP-Lounge was a great place to speak with other developers, share ideas, and have fun—free beer always helps, too. In addition, I gave talks on “Designing & Implementing RESTful Web Services” and “Filtering Tainted Data: PECL Input Filter vs. Zend_InputFilter.” Following the conference, there was some discussion around the PHP blogosphere about comments I made during my filtering presentation; a (near) future blog post will continue that discussion and provide some answers and clarification.
On the last night of the conference, a small group of us did manage to escape the confines of the hotel. We took a taxi to a local restaurant, where I had a traditional German dish and a Czech beer. After dinner, we walked several blocks until we found train tracks, and then we followed them for a kilometer or so until we came to the station. We then made it into the heart of Frankfurt, where we were able to do a little site-seeing before sampling a few more beers and returning to the hotel. I’ve posted pictures to my Flickr account.
4 Comments »
Permalink
Tags: conferences, InternationalPHPConference, InternationalPHPConference2006, IPC, ipc06, ipc2006, php, zend, ZendConference, zendconference2006
Mon, 18 Dec 2006 17:51 UTC
I recently wanted to try out the Eclipse PHP IDE, the official Eclipse project that is endorsed/backed by Zend (I’m not entirely sure about the nature of their relationship, to be honest). I already had a working Eclipse installation that I had used to try out PHPeclipse for Eclipse (not to be confused with the PHP IDE), so I didn’t want to bother downloading a brand new full package of Eclipse that includes the PHP IDE and all its requirements. So, I set about on a tedious journey to figure out how to install PHP IDE using the Eclipse Update Manager. These are my notes.
NOTE: If you don’t already have a working copy of Eclipse and you want to try out the PHP IDE, then these notes are not for you. Simply download the full package and install it. Everything should work fine out of the box. These notes are for those who have a working installation of Eclipse, want to install PHP IDE via the Update Manager, and are having trouble finding all the download sites for the PHP IDE prerequisites.
Disable PHPeclipse (if needed)
First off, if you have PHPeclipse installed, you’ll need to disable it. Navigate to Help > Software Updates > Manage Configuration. From the tree on the left, find PHPEclipse, highlight it, and choose the “Disable” link from the pane on the right.

Install the PHP IDE Prerequisites
The PHP IDE installation page lists a handful of runtime prerequisites for the PHP IDE plugin. However, it doesn’t list any URLs directing you to where the projects are located or what Update Manager URLs to use. Thus, I’m providing those links here.
For each of these prerequisites, you must follow these steps to install the package via the Eclipse Update Manager:
- Open the Update Manager at
Help > Software Updates > Find and Install…
- Select “Search for new features to install” and click the Next button
- Click the
New Remote Site… button on the right
- Enter a name and the update URL for the update site, click
OK
- Make sure the checkbox next to the new site is checked and click
Finish
- Follow the prompts to install the new package
Now that you know how to install the packages, here are the prerequisites and their update URLs:
- Web Tools Platform (WTP)
UPDATE URL: http://download.eclipse.org/webtools/updates/
Install the PHP IDE Plugin
Now that you have installed all the prerequisites, you are ready to install the PHP IDE plugin, and you shouldn’t encounter any problems now since all the prerequisites are available. To install the PHP IDE plugin, follow the same directions above to set up the PHP IDE update site in the Update Manager using the following update URL:
- PHP IDE
UPDATE URL: http://download.eclipse.org/tools/php/updates/
31 Comments »
Permalink
Tags: eclipse, install, php, phpeclipse, phpide, tutorial, zend
Fri, 15 Dec 2006 18:15 UTC
Aaron Wormus recently criticized me on IRC for putting too much thought and effort into blogging. He may have a point there. I’ve got a huge list of things I want to write about, but I haven’t put forth the effort because I do take too much time to write a post. So, here goes one for writing up a quick post . . .
I recently upgraded a few things around here (in particular, an upgrade to PHP 5.2), and I noticed two issues that occurred after the upgrade:
- My Flickr photo feed no longer worked, and
- My blogroll was no longer sorting alphabetically
I easily solved both of these issues:
The Flickr photo feed
I’m not entirely sure whether this problem was a result of the PHP 5.2 upgrade and SimpleXML becoming more particular about namespaces or Flickr simply changing the namespace string in their feed. I believe it was the latter. In short, my code stopped working because the namespace lacked a trailing slash (/). It would’ve been great if Flickr had notified everyone about this first.
The code looked something like this:
<?php
$flickr_rss = simplexml_load_file('http://www.flickr.com/services/feeds/photos_public.gne?id=49198866@N00&format=rss_200');
foreach ($flickr_rss->channel->item as $item)
{
$link = (string) $item->link;
$media = $item->children('http://search.yahoo.com/mrss');
$thumb = $media->thumbnail->attributes();
$url = (string) $thumb['url'];
$width = (string) $thumb['width'];
$height = (string) $thumb['height'];
$title = (string) $item->title;
}
?>
Note the namespace listed in $item->children(‘http://search.yahoo.com/mrss’);. It’s lacking a trailing slash. This was never a problem before, but it seems that the Flickr feed changed to include a trailing slash, so SimpleXML was no longer able to properly get the data. I simply changed it to http://search.yahoo.com/mrss/ (note the trailing slash), and all worked fine.
Blogroll sorting
This was more than likely a result of the upgrade to PHP 5.2, though I can’t be sure. My blog sorting code worked like this:
<?php
$name = array();
foreach ($blogs as $k => $v)
{
$name[$k] = $v['name'];
}
array_multisort($name, SORT_ASC, $blogs);
?>
Unfortunately, after the upgrade, this no longer worked. I had to add the SORT_STRING flag as a parameter to array_multisort() so that the line now reads:
<?php
array_multisort($name, SORT_ASC, SORT_STRING, $blogs);
?>
And that fixed it.
Just thought I’d share the info in case this helps anyone.
1 Comment »
Permalink
Tags: array_multisort, flickr, namespace, rss, simplexml