< February 2006 >
SuMoTuWeThFrSa
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
262728    
Fri, 24 Feb 2006:

I was reading through the php5 parser yesterday and something just hit me. The grammar author had created a static_scalar non-terminal which incidentally expands into a T_ARRAY '(' static_array_pair_list ')' which is wrong (IMHO, of course). The real problem was that who ever wrote the rest of the code assumed that a static_scalar would be a real scalar and it ended up with a parser which would parse the following bad code and even execute it.

<?php

function f( $a = array( 
                     array('x') => array('y')
          ))
{
    print_r($a);
}

f();
?>

Apparently andrei already tried to fix it last night (1.168) - but I don't think so. The right way to fix it would probably be to change the static_scalar expansion to exclude arrays and add a static_variable which has scalars and vectors. Then walk the whole codebase and replace as appropriate. Lot of work and lot of validation needed - which is exactly why I didn't submit a patch ;)

Still, php's the best web templating language around.

--
I never made a mistake in my life. I thought I did once, but I was wrong.

posted at: 15:23 | path: /hacks | permalink | Tags: ,