News Feed
Sections




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

PHP 10.0 Blog:
duck operator
June 05, 2008 @ 14:36:31

In this new post to the PHP 10.0 blog today, Stas talks about duck typing, a method that lets the code decide the functionality to use rather than a direct relation to a parent.

Well, if you are into duck typing style of programming, it may be interesting for you to have an object that implements certain set of functions, but not necessary declares it at class definition. Languages like Smalltalk do it all day along, so why PHP couldn't?

His example defines an interface Cow and a class MooingGrassEater and a function, CowConsumer, that does the work. A classname is passed in and an instance of that class is checked with "implements" rather than "instanceof" to see if it uses the Cow interface. He points out a place where PHP itself uses something similar in user defined streams.

0 comments voice your opinion now!
duck operator instanceof implements class interface relation


blog comments powered by Disqus

Similar Posts

Reddit.com: PSR-6 Caching Interface and PSR-5 PHPDoc enter Draft status

Federico Cargnelutti's Blog: An Alternative to Zend_Controller: The Model

Tobias Schlitt\'s Blog: A sensible place for a fluent interface

PHPMaster.com: Implementing PSR-3 with log4php

Ajaxray.com: Image manipulation in Zend Framework using PHP Thumbnailer Class v2.0


Community Events

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


library voicesoftheelephpant unittest introduction version community video language api podcast release interview opinion laravel5 example development laravel php7 framework series

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