ID: 26669 Updated by: [EMAIL PROTECTED] Reported By: trapdoor at legaciesleft dot net -Status: Open +Status: Wont fix Bug Type: Class/Object related Operating System: Linux PHP Version: 4.3.3 New Comment:
Fixed in PHP 5, won't fix in PHP 4. (workaround: Use is_array() first..) Previous Comments: ------------------------------------------------------------------------ [2003-12-19 07:30:58] trapdoor at legaciesleft dot net Description: ------------ When a class is expecting an array as in the example, it's waiting for $vars['var'], and a string is given, $vars['var'] still returns true. It picks up the first character of the string. isset($vars['var']) should return false if a string is passed. Normal arrays given to the class work fine. if the key is there, it returns true, if not then it returns false. But a string always returns true and it picks up the first character. Reproduce code: --------------- URL = http://www.legaciesleft.net/php/temp/source.php Script.php ---- <? include 'class.php'; echo "test 1: "; $class_one = new problem(array('var'=>'good')); echo "<BR>test 2: "; $class_two = new problem(array('novar'=>'bad')); echo "<BR>test 3: "; $class_three = new problem('string'); ?> Class.php ---- <? class problem{ function problem($vars) { if (isset($vars['var'])) echo $vars['var']; else echo 'array is not set'; } } ?> Expected result: ---------------- test 1: good test 2: array is not set test 3: array is not set Actual result: -------------- test 1: good test 2: array is not set test 3: s ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26669&edit=1
