开发者

Why doesn't this abstract class output anything in Php?

Why does this abstract class not work and output nothing?

<?php
abstract class Con {
    function __construct($name);
    }
}
class Shop extends Con {
    function __construct($name) {
        $this->shopname = $name;
    }
    function write() {
        echo $this->shopname;
    }
    function outputdate() {
        echo ' ' . date('Y');
    }
 开发者_如何学编程   function __destruct() {
        $this->outputdate();
    }
}


You cannot define some class in other class body. Instead, you must use PHP OOP features to extend one class from another.

class Shop extends Con{
...code goes here....
}
$shop = new Shop('shopname');
$shop->write();


You can't instantiate an abstract class. Also, you can't create a class within another class.

http://php.net/manual/en/language.oop5.abstract.php

http://en.wikipedia.org/wiki/Abstract_type

Check out this link if you are looking to subclass.

http://php.net/manual/en/keyword.extends.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜