News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

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


blog comments powered by Disqus

Similar Posts

Stuart Herbert's Blog: Learning PHP Data Objects, by Dennis Popel

WeberDev.com: PHP 101 (part 11) - Sinfully Simple (SimpleXML)

Felix Geisendorfer's Blog: A PHP developers guide to JavaScript - Part 1

Brandon Savage's Blog: 5 (Good) Lessons The Government Teaches Us About Object-Oriented Programming

VG Tech Blog: Unit Testing with Streams in PHP


Community Events





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


conference bugfix voicesoftheelephpant symfony language podcast tips laravel api threedevsandamaybe community zendserver code list framework release deployment series interview introduction

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