php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45742 Wrong class array inpretetion using constant indexes
Submitted: 2008-08-07 09:54 UTC Modified: 2008-08-07 11:45 UTC
From: kore@php.net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3CVS-2008-08-07 (CVS) OS: Linux 2.6.26-gentoo
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: kore@php.net
New email:
PHP Version: OS:

 

 [2008-08-07 09:54 UTC] kore@php.net
Description:
------------
If an array is used as a class property and the keys are constants, where two keys / constants have the same value, the second key is converted to a "strange" string.

Reproduce code:
---------------
<?php

class Constants {
    // Needs to be equal
    const A = 1;
    const B = 1;
}

class ArrayProperty {
    public static $array = array(
        Constants::A => 23,
        Constants::B => 42,
    );
}

var_dump( ArrayProperty::$array );

?>

Expected result:
----------------
Output PHP 5.2.7-dev (cli) (built: Aug  7 2008 11:12:42) (DEBUG)
array(1) {
  [1]=>
  int(42)
}

Actual result:
--------------
Output PHP 5.3.0alpha2-dev (cli) (built: Aug  6 2008 19:47:42) (DEBUG)
array(2) {
  [1]=>
  int(23)
  ["Constants::"]=>
  int(42)
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-07 11:45 UTC] dmitry@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 20:01:32 2025 UTC