Dan*_*ugg 21 php static-methods this deprecated instance-methods
虽然我理解$this
当在静态上下文中调用方法时该变量不可用,但为了帮助将我的应用程序组件彼此解耦,我认为从实例调用静态方法是有意义的.例如:
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');
Run Code Online (Sandbox Code Playgroud)
是否有计划弃用此类功能,或者我是否愿意期待对此的支持?我一起工作error_reporting(-1)
以确保一个非常严格的开发环境,并且目前还没有任何问题(PHP 5.3.6)但是我知道反向变得不受支持; 也就是说,静态调用实例方法.
归档时间: |
|
查看次数: |
14353 次 |
最近记录: |