News Feed
Jobs Feed
Sections

Recent Jobs

News Archive
David Otton's Blog:
Neat PHP tricks Casting Arrays to Objects
August 14, 2008 @ 13:38:10

David Otton has a handy little tip if you're looking for a cleaner way to deal with array data - casting it to an object.

Array notation is fine, but it can look a bit clunky when you're working with complex structures. [...] Casting the array to an object allows us to use object notation (->) and makes the code more readable.

He includes examples of the casting, showing the difference between the array and object notations including a method for creating an object based on a simple array that has basic properties built in. This sort of transformation can be useful if you want consistency through out the application - just passing objects with their properties rather than arrays.

0 comments voice your opinion now!
array object casting trick notation readable



Similar Posts

Stubbles Blog: My wishlist for PHP 6, pt1: The 'object' type hint

DevShed: Keeping Track of Objects when Using Destructors in PHP 5

PHPit.net: PHP5 Class Basics, Part 1

IBM developerWorks: What's new in PHP V5.3, Part 1: Changes to the object interface

Joshua Thompson's Blog: Return to Prototype Based Programming in PHP


Community Events









Don't see your event here?
Let us know!


conference mysql PHP5 developer cakephp zend releases package security job code release ajax zendframework framework example application PEAR book database

All content copyright, 2008 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework