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. Quote Link to comment 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. ?> Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
trq Posted November 11, 2007 Share Posted November 11, 2007 Static methods are only available in php5. Quote Link to comment 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.