While I understand the $this
variable is not available when a method is called in a static context, to assist in decoupling my application components from one-another I figured it would make sense to call static methods from an instance. For example:
class MyExample{
private static $_data = array();
public static function setData($key, $value){
self::$_data[$key] = $value;
}
// other non-static methods, using self::$_data
}
// to decouple, another class or something has been passed an instance of MyExample
// rather than calling MyExample::setData() explicitly
// however, this data is now accessible by other instances
$example->setData('some', 'data');
Are there plans to deprecate this sort of functionality, or am I right to expect support for this going forward? I work with error_reporting(-1)
to ensure a very strict development environment, and there aren't any issues as of yet (PHP 5.3.6) however I am aware of the reverse becoming unsupported; that is, instance methods being called statically.
$example::method()
will look for a class with the name$example
evaluates to, so I don't believe that will work (barring trickery with__toString()
) ... or not? I didn't expect that to work, however it appears to have. I'm curious though, syntactically (and technically) if that's the best direction. – Remedial