PHP Sadness

Syntax verbosity (arrays and array keys)

In <5.4, array syntax and key quoting, especially for large nested arrays, is very cumbersome:

$TV = array(
   "flintstones" => array(
       "series"   => "flintstones",
       "nights"   => array("monday", "thursday", "friday"),
       "members"  => array(
           array( "name" => "fred",    "role" => "lead", "age"  => 36, ),
           array( "name" => "wilma",   "role" => "wife", "age"  => 31, ),
           array( "name" => "pebbles", "role" => "kid",  "age"  =>  4, ),
       ),
   ),

   "jetsons"     => array(
       "series"   => "jetsons",
       "nights"   => array("wednesday", "saturday"),
       "members"  => array(
           array( "name" => "george",  "role" => "lead", "age"  => 41, ),
           array( "name" => "jane",    "role" => "wife", "age"  => 39, ),
           array( "name" => "elroy",   "role" => "kid",  "age"  =>  9, ),
       ),
    ),

   "simpsons"    => array(
       "series"   => "simpsons",
       "nights"   => array("monday"),
       "members"  => array(
           array( "name" => "homer", "role" => "lead", "age" => 34, ),
           array( "name" => "marge", "role" => "wife", "age" => 37, ),
           array( "name" => "bart",  "role" => "kid",  "age" => 11, ),
       ),
    ),
 );

Compare the same array from perldoc perldsc. JSON syntax would be even better (simpler keys) and also quite short.

A solution to this sadness was proposed and widely supported by users in a PHP RFC, but was shot down by the core developers.

As of PHP 5.4, one can replace array(...) with [...], solving part of the issue. Sadly, the two-character delimiter for key/value pairs (=>) and mandatory quoting of keys are still required.