Adding new php syntax

March 5, 2009 · Posted in Patches · Comment 

This is a quick patch I did to php's source code to implement some special syntax. Basically I wanted to be able to define an array like this:

$a=[ 1,2,3,4];

Get the patch here:  New array syntax for php-5.2.6-5.2.9 (997 bytes)
To get this behavior download php's source code, extract it put my patch in the source directory and  do this:

patch -p1 < new_array_zend_syntax.patch
cd Zend
./buildconf
./configure
make
cd ..
./configure
make
 

( This will only compile but not install - in case you want that just type make install at the end )
And here's a test script :

$a=[ 'key' => 'value',1,2,3];
print_r($a);

Save this script as test.php then run sapi/cli/php test.php

This was tested on php 5.2.6 and 5.2.9. I think this is probably useless for most people but it was fun to write so why not share it :)