php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
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
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: tomas_matousek at hotmail dot com
New email:
PHP Version: OS:

 

 [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 commitsRelated reports
 [2004-08-14 00:43 UTC] php at hristov dot com
AFAUK, internally the private member variables are stored in such a way that the first byte is \0, which maybe you emulate with your test case. ":private" means that the member var is private one.

shorter example for "creating" of a private variable :
php -r '$a=new stdclass();$a->$b=3;var_dump($a);'
and of "integer" member variable
php -r '$a=new stdclass();$b=3;$a->$b=3;var_dump($a);' 

andrey
 [2005-04-28 19:41 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_0.

Empty property and string properties started with '\0' are disallowed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 17:01:35 2024 UTC