In this case, I would use classes with static methods:
class Tools { static public function myMethod() { return 1*1; } } echo Tools::myMethod();
EDIT
As mentioned by Chris and yes123: if the host is already running PHP 5.3 + , you should consider using namespace . I would recommend reading an article by Matthew Weyer O'Finney Why the PHP namespace matters if you are unsure whether to switch to namespaces.
EDIT
Despite the fact that those who generalize the use of static methods as “bad practice” or “stupidity” did not explain why they thought it would be as such, which would be more constructive - they still made me rethink and re-read.
Typical arguments are that static methods can create dependencies, and because of this it is impossible to make unit testing and renaming classes impossible.
If unit testing is not used at all (perhaps programming for home / personal use or low-budget projects where no one wants to pay the extra cost of implementing a single test), this argument is, of course, outdated.
Even if unit testing is used, dependency creation of static methods can be avoided by using $var::myMethod() . That way you can still use mocks and rename the class ...
Nevertheless, I came to the conclusion that my answer is too generalized.
I think I had better write: it depends.
Since this is likely to lead to an open discussion of the pros and cons of all possible solutions, technically possible and dozens of possible scenarios and conditions, I do not want to go into it.
I now answered Chris. It already covers most of the technical capabilities and should serve you well.
Jürgen thelen
source share