标题: 关于私有成员的继承?
flynetcn
新手上路
Rank: 1



UID 417
精华 0
积分 0
帖子 23
翻译 0
原创 0
阅读权限 10
注册 2007-10-8
状态 离线
发表于 2007-12-25 10:47  资料  短消息  加为好友 
关于私有成员的继承?



<?php
class user1{
    private $name = 'flynetcn';
    private function say(){
        echo $this->name;
        echo '<br>';
    }
    public function tosay(){
        $this->say();
    }
}

class user2 extends user1 {
}

Reflection::export(new ReflectionClass('user2'));
?>

显示:
Class [  class user2 extends user1 ] { @@ E:\website\1.php 13-14 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [2] { Method [  private method say ] { @@ E:\website\1.php 4 - 7 } Method [  public method tosay ] { @@ E:\website\1.php 8 - 10 } } }
继承了私有的方法,而没有继承私有的属性。
此时可以:
$a = new user2();
$a->tosay();
输出:
flynetcn
那上面的输出是谁的属性呢?
等于调用了父类的方法和父类的属性?

顶部
wps2000
新手上路
Rank: 1



UID 34
精华 0
积分 0
帖子 73
翻译 0
原创 0
阅读权限 10
注册 2007-5-20
状态 离线
发表于 2007-12-26 12:22  资料  短消息  加为好友 
又来了....
如果你看过phpe上关于PHP5的那几篇文章就知道了,记得在那几篇文章(还是Haohappy写的)中,把这个叫做静态绑定的。

难道非得逼得PHP在反射中将父类的private方法的modifier改为 unreachable ?





顶部
 


PHPEye开源社区


当前时区 GMT+8, 现在时间是 2008-12-3 11:18

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.023549 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - PHPEye开源社区 - Archiver