kks_krishna Posted November 11, 2007 Share Posted November 11, 2007 HI, How can I define a common utility functions in the utility class and then i want to use the function in many other classes. I don't want to define in each class. Link to comment https://forums.phpfreaks.com/topic/76820-how-to-define-common-functions/ Share on other sites More sharing options...
trq Posted November 11, 2007 Share Posted November 11, 2007 (Using php5) You could define your util class as containing static methods. <?php class util { static public foo() { echo "Hello from foo!\n"; } } util::foo(); // now you can call foo() without the need to instantiate the util class. ?> Link to comment https://forums.phpfreaks.com/topic/76820-how-to-define-common-functions/#findComment-388928 Share on other sites More sharing options...
kks_krishna Posted November 11, 2007 Author Share Posted November 11, 2007 do i need to import utill class? Link to comment https://forums.phpfreaks.com/topic/76820-how-to-define-common-functions/#findComment-388930 Share on other sites More sharing options...
trq Posted November 11, 2007 Share Posted November 11, 2007 Yes you will need to include the util class in every page that uses it. Link to comment https://forums.phpfreaks.com/topic/76820-how-to-define-common-functions/#findComment-388935 Share on other sites More sharing options...
kks_krishna Posted November 11, 2007 Author Share Posted November 11, 2007 hi, I am not using PHP 5. how can use it? Link to comment https://forums.phpfreaks.com/topic/76820-how-to-define-common-functions/#findComment-388937 Share on other sites More sharing options...
trq Posted November 11, 2007 Share Posted November 11, 2007 Static methods are only available in php5. Link to comment https://forums.phpfreaks.com/topic/76820-how-to-define-common-functions/#findComment-388938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.