ID:               25816
 User updated by:  dan at wep dot net
 Reported By:      dan at wep dot net
 Status:           Open
 Bug Type:         Class/Object related
 Operating System: Linux (Redhat 9, 2.4.22)
 PHP Version:      5CVS-2003-10-10 (dev)
 New Comment:

The parse error thrown complains about the print(someData['foo']) line.
Sorry if this wasn't clear. Also expected output would probably be more
like "bar ..var_dump output.. bar.


Previous Comments:
------------------------------------------------------------------------

[2003-10-10 00:24:51] dan at wep dot net

Description:
------------
Constants defined inside classes can be defined as an array
prepopulated with key, value pairs; however this data is not directly
accessible.

It is possible to create a local variable copy of the constant at
runtime and use it to access the data.

If class constants are not meant to be able to hold array data, then a
parse error should of been thrown on the 'const' declaration.

Reproduce code:
---------------
class test {
  const someData = array('foo' => 'bar');

  function __construct() {
    $dataCopy = someData;
    print($dataCopy['foo']);  // This works
    print(var_dump(someData));  // This works (shows all array
information)
    print(someData['foo']);  // This throws a parse error
  }

}

$obj = new test();

Expected result:
----------------
bar
bar
bar

.. Jackpot! :)

Actual result:
--------------
Parse error: parse error, unexpected '[' 


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25816&edit=1

Reply via email to