php.net |  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.

<?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()
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-15 08:59 UTC] stas@php.net
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 http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net 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: Sun Dec 22 02:01:28 2024 UTC