|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-06-15 08:59 UTC] stas@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 05:00:01 2025 UTC |
The following codes didn't work as expected. There're two problems that I don't understand. First, PHP doesn't know about defined constant if test() is called from subclass. <?php define('TEN', 10); class Foo { function test() { static $arr = array(TEN => 'ten'); print_r($arr); } } class Bar extends Foo { } Foo::test(); // output: Array([10] => ten) Bar::test(); // output: Array([TEN] => ten) ?> Second, as commented, it doesn't know about const TEN too. <?php class Foo { const TEN = 10; function test() { // --- PHP will complain about this // static $arr = array(TEN => 'ten'); // --- This line cause $arr to be an empty array // without any error static $arr = array(Foo::TEN => 'ten'); print_r($arr); } } Foo::test(); // output: Array() ?>