ID: 34500
User updated by: stochnagara at hotmail dot com
Reported By: stochnagara at hotmail dot com
Status: Bogus
Bug Type: Feature/Change Request
PHP Version: 5CVS-2005-09-14 (snap)
New Comment:
Ok, then I will reformulate my feature request : Function
get_object_vars applied to stdClass returns array containing all object
properties and their values.
I'd like to see a function which is the opposite of get_object_vars,
e.g. array_to_object ($array) which converts an array to a stdClass
object with array keys as properties and array values as proerties
values.
Many users will appreciate it. See Drupal too:)
Previous Comments:
------------------------------------------------------------------------
[2005-09-14 13:09:47] [EMAIL PROTECTED]
stdClass is a dummy class that doesn't have any methods, including
constructor, so there is nothing to change.
Declare and use your class.
------------------------------------------------------------------------
[2005-09-14 13:06:10] stochnagara at hotmail dot com
I forgot: 'a' and 'b' become class members so
echo $obj->a prints 2 and echo $obj->b prints 3.
------------------------------------------------------------------------
[2005-09-14 13:04:27] stochnagara at hotmail dot com
Description:
------------
I think it will be very useful to modify stdClass constructor from
__construct() to __construct ($fields = array()).
This will make stdClass easier to work with like arrays.
Reproduce code:
---------------
$array = array ('a' => 2, 'b' => 3);
$obj = new stdClass;
$obj->a = 2;
$obj->b = 3;
//Not supported
$obj = new stdClass (array ('a' => 2, 'b' => 3));
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34500&edit=1