Late static binding....sorta :/ - Digital Sandwich - PHP

原创 2007年09月27日 18:39:00

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)

 

complexity Analysis of Late Binding

  • 2010年04月17日 17:20
  • 324KB
  • 下载

Late binding

Late binding,或者dynamic binding,是指在运行时才确定对象的方法或者函数。   在面向对象的语言中,early binding, 或者static binding,是指在...

python 延迟绑定(late binding)

#!/usr/bin/env python3 # -*- coding: utf-8 -*-' a test module '__author__ = 'Zhang Shuai' def operat...

Java 多态 后链接(late binding)与前链接(early binding) 向上转型(upcast)

使用过面向对象编程(OPP)的都知道,多态是OPP的一个主要特性之一。Java做为一种OPP语言,其也有多态特性。 那么什么是多态呢?多态指允许不同类的对象对同一消息做出响应。即同一消息可以根据发送...

[static FL]part2: binding

variable binding: val x = e val: keyword x: variable e: expression v: value(不需要做多余计算的表达式) t: type ...

PHP NDV (Not complete Digital Visa)非完整数字签证

Common\NDV.php/** * NDV (Not complete Digital Visa) * 非完整数字签证 * * +-----------------------------...

Static Binding versus Dynamic Binding

所谓“绑定(binding)”,是指建立method call(函数调用)和method body(函数本体)的关联。一切方法调用(method call)在Class文件中存储的都是一个常量池中的符...

Ice Cream Sandwich系虾米?

北京时间9月22日消息,据国外媒体报道,Android的下一个版本Ice Cream Sandwich(冰淇淋三明治)即将发布。目前,市场中居于主导地位的Android版本仍然是Froyo(冻酸奶),...
  • lj89168
  • lj89168
  • 2011年11月18日 22:16
  • 338

Dynamic Binding vs Static Binding in Java

Difference between Dynamic Binding & Static Binding in Java Dynamic Binding or Late Binding ...

8年后战争又起:Linus Torvalds was (sorta) wrong about C++

语言之争永远是热门的话题,无论你是脱离了语言限制的老手,还是初入IT的新人。2007年的时候,Linus曾在一封邮件中大骂C++。原文链接From: Linus Torvalds Subject: ...
  • smstong
  • smstong
  • 2015年03月13日 20:46
  • 1562
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章: Late static binding....sorta :/ - Digital Sandwich - PHP
举报原因:
原因补充:

(最多只允许输入30个字)