Example usage via calls outside of the class and within an object:
<?php
class foo {
private static $value = '';
public static function set($method_identifier, $value_to_pass = '') {
$static_method = 'set' . ucfirst(strtolower(trim($method_identifier)));
if(method_exists(__CLASS__, $static_method)) {
foo::$static_method($value_to_pass);
echo "\tCalling forward_static_call with pure string and value param:\n";
forward_static_call(__CLASS__ . "::" . $static_method, $value_to_pass);
echo "\tCalling forward_static_call with class, method array and value param:\n";
forward_static_call(array(__CLASS__, $static_method), $value_to_pass);
}
}
public static function setValue($value_recieved = '') {
echo "\t\tsetValue called with param of " . var_export($value_recieved, true) . "!\n";
echo "\t\tSetting Private 'value'...\n";
self::$value = $value_recieved;
echo "\t\tChecking the Private 'value':\n";
if(!empty(self::$value)) {
echo "\t\t\tPrivate 'value' was set to '" . self::$value . "' as expected!\n";
} else {
echo "\t\t\tPrivate 'value' was not set!\n";
}
self::$value = '';
}
public function __construct() {
echo "\tCalling from within constructor..\n";
foo::set('value','Something else from within the instance!');
}
}
echo "\n============ Calling by static method first ============\n";
foo::set('value','Something from outside of the foo class!');
echo "\n============ Calling by static method without a value next ============\n";
foo::set('value');
echo "\n============ Calling by createing an instance next ============\n";
new foo();
?>