Re: About PHP Implements

From: Date: Wed, 19 Dec 2007 16:53:31 +0000
Subject: Re: About PHP Implements
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-266106@lists.php.net to get a copy of this message
On Dec 19, 2007 11:17 AM, Andrew Ballard <aballard@gmail.com> wrote: > On Dec 18, 2007 4:58 PM, Jim Webber <webber@infotechnow.com> wrote: > > Hello I have a PHP4 server and I'm trying to figure out how to do > > "implements" on classes. Is there an analogous way to do this without > > PHP5 installed? > > > > It isn't inheritance in the same sense as PHP5, but you can use the > method_exists() function to check whether a given object has the > method you want to use before you try to use it. > > if (method_exists($obj, 'doSomething')) { > $obj->doSomething(); > } else { > // $obj does not support the required interface > } > > This at least allows a way for your code to enforce the interface on > an as-needed basis and recover gracefully. this is indeed the best, if not only, way to emulate interfaces in php4; i believe this was recommended some time back as well. -nathan

« previous php.general (#266106) next »