Another option:

$items = array(); // this could be any set of data or null
$oTrack = new ArrayObject($items, ArrayObject::ARRAY_AS_PROPS);

That would give you access to this kind of functionality:
http://www.php.net/~helly/php/ext/spl/classArrayObject.html

-ralph



On 2/6/09 11:43 AM, "Michael Tramontano" <[email protected]>
wrote:

> What you have there works fine, is simple, and is relatively quick so I¹m not
> sure why you¹re looking for something built-in.
>  
> That being said, an alternative is to make a class that simply copies the
> array to a private variable, and uses the magic __get and __set functions for
> access outside of the class. Perhaps something like this might help if you
> want to go in that direction:
> http://us2.php.net/manual/en/language.oop5.overloading.php#language.oop5.overl
> oading.members
>  
> Mike Tramontano
> eFashion Solutions - Sr Backend Developer
> [email protected]
>  
> 
> From: [email protected] [mailto:[email protected]] On Behalf Of A.J. Brown
> Sent: Friday, February 06, 2009 12:24 PM
> To: Zend Framework General
> Subject: [fw-general] stdClass Question
>  
> Hey guys,
> 
> This is probably more approriate for the PHP list, but I'm not subscribed with
> this email address, so I'll pose it here.
> 
> Is there a better / built in way to turn an array into a stdClass?
> 
> //TODO (is there / why isn't there) a built in way to do this?
> $oTrack = new stdClass();
> foreach( $trackData as $key => $value ) {
>              $oTrack->$key = $value;
> }
> 
> 
> I'm doing this because the user has the option of passing in either a model
> (an object type), or an array of the data that would be in the model.  But, I
> don't want to have two different code paths for processing the data.
> 
> -- 
> Ralph Schindler
> Software Engineer     | [email protected]
> Zend Framework        | http://framework.zend.com/
> 

Reply via email to