Adding new php syntax

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:

  1. $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:

  1. patch -p1 < new_array_zend_syntax.patch
  2. cd Zend
  3. ./buildconf
  4. ./configure
  5. make
  6. cd ..
  7. ./configure
  8. 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 :

  1. $a=[ 'key' => 'value',1,2,3];
  2. 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 :)

Leave a Reply