Search code examples
phpoopclassphp4

PHP 4 - Undefined class name


In PHP 4, if you use a class before it's defined you get this error:

Fatal error: Undefined class name 'foo' in...

My code is:

function do_stuff(){
  if(foo::what()) ... // this code is before the php file with the foo class is included    
}

class foo{
  function what(){
  ...
  }
}

do_stuff();

is there any workaround for this (besides telling the people who use your script to update to php5) ?


Solution

  • You could instead use:

    call_user_func(array('foo', 'what'));
    

    which would cause the class/method to be checked at runtime rather than compile time.