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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC