为什么这个抽象类在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();
    }
}

为什么这个抽象类不起作用而且什么都不输出? p>

 &lt;?php 
abstract class Con {
 function __construct($ name); 
} 
} 
class Shop extends Con {
 function __construct($ name){
 $ this-&gt; shopname = $  name; 
} 
函数write(){
 echo $ this-&gt; shopname; 
} 
函数outputdate(){
 echo''。 日期('Y'); 
} 
函数__destruct(){
 $ this-&gt; outputdate(); 
} 
} 
  code>  pre> 
  div>

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