From: tomas_matousek at hotmail dot com
Operating system: WinXP
PHP version: 5.0.0RC3
PHP Bug Type: Zend Engine 2 problem
Bug description: Strange behavior of field which names are not strings
Description:
------------
If I try to use variable with non-string name (e.g.
$x = 10; $$x = ...) the name is converted to a string using standard
conversion rules. That's ok.
But this doesn't work on object's field which is IMHO a bug and it implies
some a buggy behavior.
See the code bellow.
It seems that by:
$x = null;
$a->$x = "whatever";
one can somehow create a private variable (or something like that, don't
know what ":private" means)!
Moreover, there is possibly a bug in get_object_vars when a field name is
a numeric string (e.g. "10") (compare the first item of results of
get_object_vars and var_dump).
Reproduce code:
---------------
function field_names_test()
{
$a = new stdClass();
$x = 10;
$a->$x = "int(10)";
$x = "10";
$a->$x = "string('10')";
$x = "";
$a->$x = "string('')";
$x = null;
$a->$x = "null";
$x = 1.8;
$a->$x = "double(1.8)";
$x = false;
$a->$x = "bool(false)";
$x = array(1,2,3);
$a->$x = "array(1,2,3)";
var_dump(get_object_vars($a));
var_dump($a);
}
field_names_test();
Expected result:
----------------
array(4) {
["10"]=>
string(12) "string('10')"
[""]=>
string(11) "bool(false)"
["1.8"]=>
string(11) "double(1.8)"
["Array"]=>
string(12) "array(1,2,3)"
}
object(stdClass)#1 (4) {
["10"]=>
string(12) "string('10')"
[""]=>
string(11) "bool(false)"
["1.8"]=>
string(11) "double(1.8)"
["Array"]=>
string(12) "array(1,2,3)"
}
Actual result:
--------------
array(3) {
[10]=>
string(12) "string('10')"
["1.8"]=>
string(11) "double(1.8)"
["Array"]=>
string(12) "array(1,2,3)"
}
object(stdClass)#1 (4) {
["10"]=>
string(12) "string('10')"
[":private"]=>
string(11) "bool(false)"
["1.8"]=>
string(11) "double(1.8)"
["Array"]=>
string(12) "array(1,2,3)"
}
--
Edit bug report at http://bugs.php.net/?id=29015&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29015&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29015&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=29015&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29015&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29015&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29015&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29015&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29015&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29015&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29015&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29015&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29015&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29015&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29015&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29015&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29015&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29015&r=float