返回顶部

收藏

php面向对象:调用重写的方法

更多
<html>
<head>
<title>Calling an Overridden Method</title>
</head>
<body>
<?php
class FirstClass{
    var $name = 'Joe';
    function FirstClass( $n ) {
        $this->name = $n;
    }
    function sayHello() {
        print 'my name is $this->name<br>';
    }
}

class second_class extends FirstClass {
     function sayHello() {
        print 'calling method from parent class -- ';
        FirstClass::sayHello();
     }
}

$test = new second_class('sub class');
$test->sayHello();

?>
</body>
</html>

标签:PHP,OOD

收藏

0人收藏

支持

0

反对

0

发表评论