Andrew Ballard wrote:
On Dec 18, 2007 4:58 PM, Jim Webber <[EMAIL PROTECTED]> 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
}

but that means you have to change all the calling functions, which becomes a real PITA.

I think you could do something with the constructor but how well it works I don't know :)

class x
{
  function x()
  {
    $required_methods = array('a','b','c');
    foreach ($required_methods as $req)
    {
       if (!method_exists($this, $req))
       {
die("You need to create $req method for class " . get_class($this));
       }
    }
  }
}

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to