129-PHP子类不能访问父类private修饰的类成员

<?php
    class father{        //定义father类
        //定义private修饰的类成员和方法
        private $hair='curly hair';
        private function smoke(){
            echo '我有吸烟的习惯。';
        }
    }
    class son extends father{        //定义继承自father类的son类
        //定义访问private修饰的类成员的方法
        public function get_property(){
            $this->hair;
            $this->smoke();
        }
    }
    $son=new son();        //实例化son类的对象
    $son->get_property();        //调用对象的方法
?>

猜你喜欢

转载自www.cnblogs.com/tianpan2019/p/11013960.html