php开源嘛
首页 | English | MySql数据库 | Php编程 | 建站杂烩 | 系统服务器 | 资源共享 | 专题 | 才桀网 | 支持论坛
  当前位置:主页>English>文章内容
Late static binding....sorta ...
来源:phpeye 作者:本站整理 发布时间:2007-09-27  

Late static binding....sorta ...

 phpmaThe 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.

phpmaIf 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.

phpmaThis 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
{
}
 

phpmaIf 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)phpma

 


(阅读次数:
上一篇:MySQL实例管理器并创建用户账户   下一篇:对网站运营可能失败的N种原因
[收藏] [推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论
  热点文章
·什么是Smaty?一个php模板引擎.
·Mysql中innodb 和myisam的区别?
·what is apache? 服务器
·What is PHP?
·Apache是一款流行的伺服器
·what is openssh?而ssh又是什么?
·What is MySQL? MySQL数据库
·what is Linux? 操作系统
·php|works, Session Day 1
·What is EditPlus?How to Instal
·php表达式之explode() 分割字符
·Ajax技术(五)用AjaxTags简化Ajax
  相关文章
·What is EditPlus?How to Instal
·Mysql中innodb 和myisam的区别?
·php|works, Session Day 1
·什么是Smaty?一个php模板引擎.
·what is openssh?而ssh又是什么?
·php表达式之explode() 分割字符
·Ajax技术(一)用AjaxTags简化Ajax
·Ajax技术(二)用AjaxTags简化Ajax
·Ajax技术(三)用AjaxTags简化Ajax
·Ajax技术(四)用AjaxTags简化Ajax
·Ajax技术(五)用AjaxTags简化Ajax
·Ajax 能够做什么?

关于我们 | 本站声明 | 友情连接 | 诚邀加盟 | 网站地图
版权Power by DedeCms   技术支持QQ =>> 罗江游鱼   Jacking  后台登陆
Copyright @ 2007 公司地址:柳州市东环路268号 邮编:545006 电话:15920389818 桂ICP备07006725号