News Feed
Sections




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

QaFoo.com Blog:
Struct classes in PHP
January 24, 2011 @ 09:59:22

On the QaFoo blog today there's a new post looking at building struct classes in PHP (by Kore Nordmann) as a replacement - and a step up - from storing data in structures like arrays.

In Apache Zeta Components and in several of my own projects we are using - so called - struct classes to solve this issue: The struct classes do not define any methods but just contain documented properties. They just deal as a data container, similar to a hash map.

He mentions a few benefits and drawbacks to using this approach including the fact that, while they're easier to document and can make things clearer in your IDE, they also are objects and are passed by reference by default (leading to possible unintended behavior). That being said, he includes a sample implementation so you can judge for yourself. The example defines a Location with a city and state properties that extends a base Struct class.

0 comments voice your opinion now!
struct class example array


blog comments powered by Disqus

Similar Posts

Evolt.org: Working With Fractions In CSS and PHP

Attila Szabo's Blog: Send SMS messages from your website through smsBug gateway

Rasmus Lerdorf's Blog: ZeroMQ + libevent in PHP

Cocoliso's Blog: Adding A Syntax Highlighter To Your Site: The Power Of Geshi

Ian Selby's Blog: Put Your PHP App on Steroids - Optimizing with APC Cache


Community Events

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


example podcast introduction series conference php7 configure community opinion api interview laravel application release symfony2 voicesoftheelephpant performance composer part2 framework

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