#26669 [NEW]: passing a string to a class when it's expecting an array gives bad results
From: trapdoor at legaciesleft dot net
Operating system: Linux
PHP version: 4.3.3
PHP Bug Type: Class/Object related
Bug description: passing a string to a class when it's expecting an array gives bad results
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 bug report at http://bugs.php.net/?id=26669&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26669&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26669&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=26669&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=26669&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=26669&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=26669&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=26669&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=26669&r=support
Expected behavior: http://bugs.php.net/fix.php?id=26669&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=26669&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=26669&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=26669&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26669&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=26669&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=26669&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=26669&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26669&r=float
Thread (2 messages)
- trapdoor at legaciesleft dot net