[drupal-devel] array2object improvement

Moshe Weitzman weitzman at tejasa.com
Fri Sep 16 16:52:08 UTC 2005

Gabor Hojtsy wrote:
>>>Forms with nested groups of elements have to be navigated as keyed
>>>arrays: $form['admin']['options'] for example. When a newly loaded
>>>object is prep'd for use using object2array($object), it flattens the
>>>properties to $form['options'] and so on. if you're not expecting it,
>>i think array2object and object2array could be simplied like so:
>>function array2object($arr) {
>>  return (object) $arr;
>>this would avoid the flattenning that you mention, as well as save some
>>cycles. anyone care to test this and submit a patch if it works?
> There is no need to have this simple function if a casting works in all
> cases in Drupal.
> Goba

It doesn't work in all cases. Casting is not valid in some contexts. 
Gives a PHP error. I don't recall exactly how to reproduce.

More information about the drupal-devel mailing list