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: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: trapdoor at legaciesleft dot net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 05:01:28 2025 UTC