为什么这个抽象类不能工作并且没有输出?
<?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();
}
}
不能在其他类体中定义某些类。相反,您必须使用PHP OOP特性来从一个类扩展另一个类。
class Shop extends Con{
...code goes here....
}
$shop = new Shop('shopname');
$shop->write();
不能实例化抽象类。此外,您不能在另一个类中创建一个类。
http://php.net/manual/en/language.oop5.abstract.php http://en.wikipedia.org/wiki/Abstract_type如果你正在寻找子类,请查看此链接。
http://php.net/manual/en/keyword.extends.php