Jump to content

non static functions being called as static methods?


guhels

Recommended Posts

Hello there.

 

I am following the Joomla Hello World MVC (part1) component tutorial but theres something that i cant understand.

 

On hello.php theres this code:

// Require specific controller if requested
if($controller = JRequest::getWord('controller')) {
    $path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
    if (file_exists($path)) {
        require_once $path;
    } else {
        $controller = '';
    }
}

 

But looking at the JRequest class, the function getWord is not defined as static:

function getWord($name, $default = '', $hash = 'default')
   {
      return JRequest::getVar($name, $default, $hash, 'word');
   }

 

So, how can i call a static method if its not defined as static!? I think im missing something big here...

Currently you can call non-static (dynamic) methods as much as you want, but you cannot call dynamic methods statically.  Also, the ability to call dynamic methods statically will throw a fatal error or something in PHP 6 (don't remember exactly how they decided to handle it), so you might want to avoid it.

Thanks for all the answers!

 

This http://www.phpbuilder.com/manual/en/language.oop5.paamayim-nekudotayim.php helped a lot.

 

Using the :: operator doesnt necessarily mean (only) that im calling a static method, i can use it just to call a method outside a class, which is whats happening here.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.