Bug #12398: Problem with associative arrays, used within classes
| From: | flying at dom dot natm dot ru | Date: | Thu, 26 Jul 2001 13:35:43 +0000 |
| Subject: | Bug #12398: Problem with associative arrays, used within classes | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-61058@lists.php.net to get a copy of this message | ||
From: flying@dom.natm.ru
Operating system: Windows 2000
PHP version: 4.0.6
PHP Bug Type: Class/Object related
Bug description: Problem with associative arrays, used within classes
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'.
--
Edit bug report at: http://bugs.php.net/?id=12398&edit=1