News Feed
Sections




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

Zend Developer Zone:
Trait-like Functionality for PHP
April 07, 2010 @ 10:05:52

In a new tutorial posted on the Zend Developer Zone today Steve Hollis looks at something several PHP developers have said they want to seen in the language - traits - and how, until then, you can use traits now (well, sort of).

So why do we need traits, anyway? PHP is a single inheritance language, meaning that each class can only extend one other. This allows us to build logical class hierarchies which extend functionality in a "vertical" way. [...] What we need is a means of re-using code other than simple inheritance. That's where traits come in. Traits are classes containing a collection of methods, usually relating to a particular behaviour.

He shares a way that you can mimic some of the functionality that traits would give you (full code is available here) with an abstract trait class, reflection and a "superclass" that's extended to pass off the requests to the correct child object.

0 comments voice your opinion now!
trait functionality tutorial mimic


blog comments powered by Disqus

Similar Posts

HowToForge.com: LAMP Installation On Ubuntu 6.06 For Linux Noobs

Community News: Zend Releases Speaker List for ZendCon 2006

ThinkPHP Blog: Accessing NTLM secured resources with PHP

DevShed: Completing a Search Engine with MySQL and PHP 5

Slawek Lukasiewicz's Blog: Zend Framework: logging with Firebug and FirePHP


Community Events

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


interview project series language yii2 voicesoftheelephpant composer opinion api application part2 example php7 community podcast list introduction symfony framework laravel

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