guhels Posted August 7, 2008 Share Posted August 7, 2008 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... Link to comment https://forums.phpfreaks.com/topic/118636-non-static-functions-being-called-as-static-methods/ Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 As long as you don't reference $this, the parser allows it. >_> Link to comment https://forums.phpfreaks.com/topic/118636-non-static-functions-being-called-as-static-methods/#findComment-610750 Share on other sites More sharing options...
corbin Posted August 7, 2008 Share Posted August 7, 2008 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. Link to comment https://forums.phpfreaks.com/topic/118636-non-static-functions-being-called-as-static-methods/#findComment-611165 Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 Yeah, I wouldn't suggest doing it, even though you can. Link to comment https://forums.phpfreaks.com/topic/118636-non-static-functions-being-called-as-static-methods/#findComment-611167 Share on other sites More sharing options...
guhels Posted August 8, 2008 Author Share Posted August 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/118636-non-static-functions-being-called-as-static-methods/#findComment-611229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.