Late static binding....sorta :/ - Digital Sandwich - PHP
来源:互联网 发布:township淘宝绿钞原理 编辑:程序博客网 时间:2024/06/17 05:17
The good news is late static binding has been introduced into head and looks like it will be merged into 5.3 before it is released. The horrible news is I really don't think the patch went as far as it needs to.
If you look at the original posts that cropped up about a year and a half ago the whole purpose of late static binding was to allow the same kind of flexibility provided by inheritance of standard class methods for static methods, properties, and constants. This wouldn't really open the door for any grandios, new kind of applications, it would just allow a new way to code libraries the most prominant example being an Active Record Library.
This is now possible, however I think there is a very unfortunate limitation that I brought up a few times on the Internals mailing list to apparently no avail. The problem is with the fact that static will ALWAYS return the 'resolved' name of the class used to call the current function. So, imagine the following method:
class Foo
{
//...
static public function test()
{
return static::$some_property;
}
//...
}
class Bar extends Foo
{
}
If you call test using Foo::test() then static:: will resolve to the 'Foo' class. If you call it using Bar::test() then static:: will resolve to 'Bar'. This is correct and works well for simple inheritance. However things start taking a downward turn the more you use inheritance. Consider the following change to Bar and the addition of a new class Bar_Child:
class Foo
{
//...
static public function test()
{
return static::$some_property;
}
//...
}
class Bar extends Foo
{
static public function test()
{
// Do some work specific to Bar
return parent::test();
}
Truncated by Planet PHP, read more at the original (another 1921 bytes)
- Late static binding....sorta :/ - Digital Sandwich - PHP
- Late binding
- C#的late binding
- 透明模拟PHP5.3中的“迟静态绑定(Late static binding)”
- get_called_class — 后期静态绑定("Late Static Binding")类的名称
- PHP中的后期静态绑定(Late Static Bindings )
- JS中的very late binding
- C++的Early Binding和Late Binding
- late-binding, Compile time, run-time, polymorphism
- python 延迟绑定(late binding)
- Static Binding versus Dynamic Binding
- python关于late binding和作用域链的理解
- [static FL]part2: binding
- java中转型(upcasting)与动态绑定(dynamic binding)或者后期(late binding)细节
- java中转型(upcasting)与动态绑定(dynamic binding)或者后期(late binding)细节
- Java 多态 后链接(late binding)与前链接(early binding) 向上转型(upcast)
- Dynamic Binding vs Static Binding in Java
- Exposing COM interfaces of a .NET class library for Late Binding
- 无锁编程与分布式编程那个更适合多核CPU?
- VB复制文件源代码
- CamGameSDK 摄像头游戏SDK提供测试版本。欢迎使用
- VB压缩/修复Access数据库操作源代码
- 常用字符编码
- Late static binding....sorta :/ - Digital Sandwich - PHP
- vc查看宏展开之后的结果的查看方式
- 常用的网页技巧
- Windows CE 6.0的技术发展与突破
- 网页代码常用小技巧!
- AutoStartApplication
- 我的软件-网页收藏夹
- 数据库运用_通过 UPDATE 语句使用来自另一个表的信息
- XML和JavaScript