php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12398 Problem with associative arrays, used within classes
Submitted: 2001-07-26 09:35 UTC Modified: 2001-10-21 19:41 UTC
From: flying at dom dot natm dot ru Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.6 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 + 1 = ?
Subscribe to this entry?

 
 [2001-07-26 09:35 UTC] flying at dom dot natm dot ru
 There seems to be a problem with associative arrays, used within classes.
But this problem persist only in arrays, which are use contants as its keys.
There is a small test case which demonstrates a problem:

<?php
define("constant_1",1);
define("constant_2",2);
define("constant_3",3);

class myClass
{
    var $arr = array(
            constant_1 => "value 1",
            constant_2 => "value 2",
            constant_3 => "value 3"
        );

    function testFunc($index)
    {
        return((isset($this->arr[$index]))?'true':'false');
    }
};

$class = new myClass();
echo $class->testFunc(constant_2);
?>

 It is easy to see, that this piece of code must write 'true' as its result, because
testFunc() method called with constant, which is actually present in array.
But testFunc() returns 'false' instead. It's because array keys are incorrectly treated as
strings instead of actual constant values (so, for example $class->testFunc("constant_2"))
will return 'true'.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-21 19:41 UTC] sniper@php.net
Works for me with PHP 4.1.0RC1

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 12 09:01:30 2024 UTC