-2

问题:比较这两段代码,为什么第一段没有打印出来?
当我使用eclipse运行这些代码时,什么也没发生,我不知道为什么它不打印“构造正在运行”。

但是,当我运行第二段代码时,它打印出:
“构造正在运行……”
“管理器构造正在运行……”
为什么?

第一段:

<?php
class Employee 
{
    protected $name;
    protected $title;

    function _construct()
    {
      echo "The constrcut is running..." . '<br>'';
    }   
}
$employee = new Employee();
?>

第二段

<?php
class Employee 
{
    protected $name;
    protected $title;

    function _construct()
    {
      echo "The constrcut is running..." . '<br>'';
    }   
}

class Manager extends Employee
{

    function __construct()
    {
      parent:: _construct();
      echo  "The Manager construct is running...";
    }
}
 $employee = new Manager();
?>
4

1 回答 1

0

在课堂上替换Employee

function _construct()
{
  echo "The constrcut is running..." . '<br>'';
}  

和:

function __construct()
{
  echo "The constrcut is running..." . '<br>'';
}  

注意双下划线 ( __)。


你也有一个语法错误:

echo "The constrcut is running..." . '<br>'';
-------------------------------------------^ Why two 's?
于 2013-03-31T03:56:07.523 回答