News Feed
Sections




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

Gonzalo Ayuso:
Multiple inheritance with PHP and Traits
December 19, 2012 @ 13:17:48

Gonzalo Ayuso has a new post today showing how you can use traits in PHP to simulate a kind of multiple inheritance.

Multiple inheritance isn't allowed in PHP. [It's not] possible with PHP (in Java is not possible either), but today we can do something similar (is not the exactly the same) with Traits. Let me explain that: Instead of classes we can create Traits.

He includes a code example showing the creation of two traits, "Base1" and "Base2", that are implemented (via "use") and the calls to methods on each. He also points out the error condition and message that can come up when there's a conflict in the method names between two or more traits. This is relatively easy to solve with the mapping ability of the "use" statement (code example included for that too).

0 comments voice your opinion now!
multiple inheritance traits python example mapping use


blog comments powered by Disqus

Similar Posts

PHPMaster.com: PHP Traits: Good or Bad?

Felix Geisendorfer's Blog: My new best friend - PHP's create_function()

PHPBuilder.com: Intro to PHP

Gonzalo Ayuso's Blog: New features in PHP5.4 alpha1

Chris Hartjes' Blog: The Devilís In The Details (or, Handling Sequences in Postgres in CakePHP)


Community Events





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


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

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