define()d constants in constant arrays break on inheritance

From: Date: Thu, 05 Jun 2003 08:56:52 +0000
Subject: define()d constants in constant arrays break on inheritance
Groups: php.internals 
Request: Send a blank email to internals+get-2178@lists.php.net to get a copy of this message
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.

« previous php.internals (#2178) next »