|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23384 static array accessed from subclass
Submitted: 2003-04-28 11:44 UTC Modified: 2003-06-15 08:59 UTC
From: thixit at yahoo dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2003-04-28 (dev) OS: Windows 98
Private report: No CVE-ID: None
 [2003-04-28 11:44 UTC] thixit at yahoo dot com
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.

define('TEN', 10);
class Foo {
    function test() {
        static $arr = array(TEN => 'ten');


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.

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');


Foo::test();    // output: Array()


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-15 08:59 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

The first form will not work, since it is ambigious, so I don't think it is possible to make it work right. The second form should be working now. 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 21:01:33 2024 UTC