php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39242 Cannot declare a static array with an index
Submitted: 2006-10-23 20:30 UTC Modified: 2006-10-23 20:36 UTC
From: z_rules55 at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.6 OS: WinXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: z_rules55 at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-10-23 20:30 UTC] z_rules55 at hotmail dot com
Description:
------------
I would have thought that I could declare a static array in a class with an index in the declaration, but I can't. I must instead use array() to specify the desired index and value. Nowhere in the docs, that I could find, does it say that you can't specify an index in a static array declaration.

I saw in another bug that PHP does not allow the use of variable data at compile time, and I guess since static variables are dealt with at compile time, you can't be assigning data to a variable index. But even if the index is define()ed beforehand, it still doesn't work.

Reproduce code:
---------------
<?php
define('INDEX', 'index');
class myclass {
    // Does not with either the string 'index' or
    // the constant INDEX.
    public static $variable['index'] = 'some value';
  //public static $variable = array('index' => 'some value'); This does work.
}
echo myclass::$variable['index'];
?>



Expected result:
----------------
some value

Actual result:
--------------
Parse error: parse error, unexpected '[', expecting ',' or ';' in ... on line 6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-23 20:36 UTC] tony2001@php.net
Yes, this is expected behaviour.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Mar 12 10:01:31 2025 UTC