A Bug’s Life from 3 to 5

15 03 2013

http://www.flickr.com/photos/inekesmit/3491358274/

dandelion and bug by smitje

This is the tale of a bug that someone reported back in September 1999 (bug 2341), when PHP3 ruled. That’s the time when PHP and went together like bread and butter. The version the bug filer reported was PHP3.0.12 which was unable to dereference an array literal. Thus writing the following code would produce a parser error message :

<?php
$i=0;
echo array("Su","Mo","Tu","We","Th","Fr","Sa")[$i];

Nine months later, June 2000, one of the core devs realized that the bug was really more a feature request and moved it. There the user’s report might have languished except that JimW (Jim Winstead? He is one of the original 10 developers of The PHP Group) refiled the report as a bug for PHP4. But, the bug failed to attract any attention. Nearly a year later, Sterling Hughes (the gentleman responsible for originating SmartyTemplates and devising SimpleXML), reviewed the report and felt it was an impossible request, remarking “No way, the WTF is to high :)” Wish he had clarified that statement with some specific criticisms. Expressions like “WTF” are more than just vulgar or crude; one is unable to discern from such a general catch-all term, exactly what the blazes the issue(s) precisely is or are.

You might think that would be the end of the matter. But, it wasn’t! 🙂

Years later in 2011, a core dev Xinchen Hui (aka laruence) chanced upon a similar feature request for PHP5 (bug #60408) and sought to provide the necessary functionality. Of course, anytime someone wishes to officially change PHP, there now needs to be an RFC (formal proposal requesting comments) and in this case that proposal is RFC: Const array/string dereference

Two weeks after the RFC appeared, the RFC proposer called for a vote. Whew, that sure makes up for all those years of lost time. Obviously, laruence had figured out how to implement the required support for the feature. But one month later Dimitry Stogov, a senior core dev, discovered that laruence’s patch had a problem. So, back to the drawing board to amend the patch which laruence successfully committed a few months later in April 2012.

Interestingly, even though the voting period was unusually long, lasting months rather than weeks, starting in December 2011 and ending in April 2012, only nine eligible individuals voted, despite there being perhaps hundreds of others who could have cast a ballot. The nine voted unanimously for this long, overdue feature. None included anyone from the famous trio of Rasmus Lerdorf, Andi Gutmans and Zeev Suraski. How is it that a feature that Sterling Hughes regarded as too hot to handle had over the years become too insignificant to merit more people devoting a click to it?

I tested the following code snippet which is a modification of some old code I found in a blog entry from 2004 (see http://www.dasgenie.com/scrap/archives/2004_01.html) which I tweaked as follows, particularly for the benefit of English speakers:

<?php

function MyArray() {
    return array('nums' => array('one','two','three'));
}
$numArr1 = myArray()['nums'];
$numArr2 = array('nums' => array('one','two','three'))['nums'];

var_dump($numArr1, $numArr2);

In PHP5.5, the code runs flawlessly yielding the following output:

array(3) {
  [0]=>
  string(4) "one"
  [1]=>
  string(4) "two"
  [2]=>
  string(4) "three"
}
array(3) {
  [0]=>
  string(4) "one"
  [1]=>
  string(4) "two"
  [2]=>
  string(4) "three"
}    

So, one vacuum cleaner down, more to go. And, oh yeah, PHP still rocks!

This work is licensed under a Creative Commons License

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: