|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26669 passing a string to a class when it's expecting an array gives bad results
Submitted: 2003-12-19 07:30 UTC Modified: 2003-12-19 08:04 UTC
Avg. Score:2.7 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: trapdoor at legaciesleft dot net Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 4.3.3 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: trapdoor at legaciesleft dot net
New email:
PHP Version: OS:


 [2003-12-19 07:30 UTC] trapdoor at legaciesleft dot net
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:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-19 08:04 UTC]
Fixed in PHP 5, won't fix in PHP 4. (workaround: Use is_array() first..)

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Feb 09 02:05:49 2023 UTC