Liquid Fire Posted March 9, 2007 Share Posted March 9, 2007 is it true that it is not possible to over functions/class methods in php? Quote Link to comment https://forums.phpfreaks.com/topic/42019-function-overloading/ Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Everything is possible in its own work around. Here is an example of overloading a function in PHP <?php class a { function a() { // constructor $this->b = new b(); } function overLoad() { // extra data here return $this->b->overLoad() "!!!"; } } class b { function b() { // constructor } function overLoad() { // extra data here return "The cat is fat"; } } ?> Another alternative might be this (I have not tested this) <?php class a extends b { function a() { // constructor } function overLoad() { // extra data here return b::overLoad() . "!!!"; } } class b { function b() { // constructor } function overLoad() { // extra data here return "The cat is fat"; } } ?> Now as for processing time for the first one, it should not be too bad for 1 class etc. But if you have 5 classes you are trying to do that to, your processing time increases dramatically. I am not sure what the second one result is. Either way if you test it out let us know what you find. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42019-function-overloading/#findComment-203780 Share on other sites More sharing options...
Liquid Fire Posted March 9, 2007 Author Share Posted March 9, 2007 Yea that is too much of a work around for have overloading functions/method. maybe one day it will, i'll just wait till then. Quote Link to comment https://forums.phpfreaks.com/topic/42019-function-overloading/#findComment-203799 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Yea, I found that out the hard way. Oh well all that Java knowledge down the tube =) PHP 5 may support overloading, I am not sure. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42019-function-overloading/#findComment-203814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.