php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35509 string constant as array key has different behavior inside object
Submitted: 2005-12-01 20:02 UTC Modified: 2005-12-05 15:13 UTC
From: bill dot finn at sellingsource dot com Assigned: dmitry (profile)
Status: Closed Package: Arrays related
PHP Version: 5CVS-2005-12-01 (CVS) OS: Gentoo 2.6.9
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: bill dot finn at sellingsource dot com
New email:
PHP Version: OS:

 

 [2005-12-01 20:02 UTC] bill dot finn at sellingsource dot com
Description:
------------
When using a constant of '01' as an array key inside of a class, it converts the key to the integer 1.  Outside of a class, it leaves it as '01'.

Reproduce code:
---------------
class mytest
{
  const classConstant = '01';

  private $classArray = array( mytest::classConstant => 'value' );

  public function __construct()
  {
    print_r($this->classArray);
  }
}

$classtest = new mytest();

define( "normalConstant", '01' );
$normalArray = array( normalConstant => 'value' );
print_r($normalArray);


Expected result:
----------------
Array
(
    [01] => value
)
Array
(
    [01] => value
)


Actual result:
--------------
Array
(
    [1] => value
)
Array
(
    [01] => value
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-01 21:08 UTC] tony2001@php.net
Dmitry, please take a look at it.
 [2005-12-05 09:57 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_1.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Feb 01 19:01:32 2025 UTC