I do not think that you can honestly not be straightforward. In any case, would it not be better to use utility classes? There is nothing for OOP, look at this:
<?php class HTMLUtil { public static function filter($str) {...} public static function entities($str) {...} public static function encode($str) {...} ...etc... } ?>
The Static Helper / Utility classes that group related functionality are easy to combine, just declare your functions as static :
Declaring classes or methods as static makes them available without having to instantiate the class.
Now you can use __autoload . You do not need to instantiate these classes to use any of your static functions, and this makes your code more readable (if a little more verbose). I always find it more satisfactory to do something like:
echo HTMLUtil::filter($str);
instead:
echo filter($str);
If necessary, you can also declare a private constructor in your utility classes to prevent them from being created, to emphasize that their "just a bunch of related functions":
private __construct() {...}
To call a static function from another function inside the same class, you would do this using the self keyword (which refers to the same class, not an instance of an object or class):
public static function foo() { echo self::bar() . '..and some foo'; }
karim79
source share