Incorrect behavior of member vars(non string ones)-numeric mem vars und others
| Bug #29015 | Incorrect behavior of member vars(non string ones)-numeric mem vars und others | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2004-07-05 15:02 UTC | Modified: | 2005-04-28 19:41 UTC |
|
||||||||||
| From: | tomas_matousek at hotmail dot com | Assigned: | ||||||||||||
| Status: | Closed | Package: | Scripting Engine problem | |||||||||||
| PHP Version: | 5CVS-2005-03-06 | OS: | * | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2004-07-05 15:02 UTC] tomas_matousek at hotmail dot com
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)"
}
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2004-08-14 00:43 UTC] php at hristov dot com
[2005-04-28 19:41 UTC] dmitry@php.net