php.net |  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
Votes:3
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:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-12-19 07:30 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC