PHP:不能使用继承.它找不到类


PHP: Can't use inheritance. It won't find the class

我达到了继承的上限,但我不能使用它们,即使我尝试使用我正在学习的书中的例子。即使所有文件都在同一文件夹中,错误也是:

"致命错误:在第 2 行的 C:''Program Files (x86)''EasyPHP-Devserver-16.1''eds-www''Learning''classes''son.php 中找不到类'mother'"

让我展示一个我创建的示例来解释。

文件: 母亲.php

    <?php
    class mother
    {
       public $word= "Hello!!!";
       function printWord()
       {
         echo $word;   
       }
     }
     ?>

文件: 儿子.php

<?php 
  class son extends mother
   {
     function printWord()
     {
      parent::printWord();
     }
   }  
?>

文件: 测试.php

<?php
include 'son.php';
$test = new son();
$test->printWord();
?>

结果:

错误:

致命错误:在第 2 行的 C:''Program Files (x86)''EasyPHP-Devserver-16.1''eds-www''Learning''classes''son.php 中找不到类"mother"

为什么会这样?如果它在同一文件夹中,为什么找不到该类?!

还需要包含mother.php。否则,它找不到错误状态的类。

朴素的例子:

测试.php

<?php
include 'mother.php'
include 'son.php';
$test = new son();
$test->printWord();
?>

但还有更好的方法

儿子.php

<?php 
  require_once 'mother.php'
  class son extends mother
   {
     function printWord()
     {
      parent::printWord();
     }
   }  
?>