php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30862 Static array with boolean indexes
Submitted: 2004-11-22 16:49 UTC Modified: 2005-02-12 17:40 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: melnikow at hotbox dot ru Assigned: helly
Status: Closed Package: Arrays related
PHP Version: 5.0.3 OS: *
Private report: No CVE-ID:
 [2004-11-22 16:49 UTC] melnikow at hotbox dot ru
Description:
------------
With use of static array with boolean indexes inside the class methods occurs implicitly converting boolean to integer. 

Reproduce code:
---------------
<?php
class ClassA
{
  public static $arr =
    array(FALSE => "This is FALSE",
          TRUE  => "This is TRUE");
  
  static public function test()
  {
    $arr = array(FALSE => "This is FALSE",
                 TRUE  => "This is TRUE");
    
    echo self::$arr[TRUE];
    echo "<br>".$arr[TRUE];
  }          
}

ClassA::test();
?>

Expected result:
----------------
This is TRUE 
This is TRUE

Actual result:
--------------
Notice: Undefined offset: 1 in ... on line 13 
This is TRUE

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-22 21:21 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2004-11-22 22:36 UTC] derick@php.net
This is actually valid, a shorter script:
php -r 'class T{static $a=array(false=>"false",true=>"true");} print_r(T::$a);'

 [2004-11-23 02:29 UTC] melnikow at hotbox dot ru
Yes :) I agree, manual tells about implicitly converting, but there is no way to get access to array with any index of 0, 1, FALSE, TRUE.
 [2005-02-12 17:40 UTC] helly@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-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 20:01:57 2014 UTC