This bug has been around a long time; I actually thought that define()s
wouldn't work at all in scalar initializers until today :)

<?php
error_reporting(E_ALL);
define('A', 200);
class Foo { var $bar = array(A => 'a'); }
class Bar extends Foo {}

var_dump(get_class_vars('Foo')); // bar => array(200 => 'a')
var_dump(get_class_vars('Bar')); // bar => array('A' => 'a')
?>

If you comment out the first get_class_vars line, then the output for
Bar is correct (200 => 'a').

I tracked down the problem to zval_update_constant(); when it walks the
array it turns of the IS_CONSTANT_INDEX bit on the original zval.  So,
when it is called subsequently it doesn't know that it should lookup the
constant name.

The patch at http://www.php.net/~wez/define_inherit.diff fixes this
problem by making a copy of the element and clearing the bit in the
copy, and removing the reference to the original element from the array.

--Wez.


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to