0

我在哪里放置包括以接近正确注册?我尝试在 ATE 中同时包含命令库和关闭,并且我尝试在 ATE 中仅包含命令库,在命令库中包含关闭...无论我做什么,它都会显示未找到关闭。

类.CommandBase.php

  <?php
      abstract class CommandBase {
      // variables
      // abstract functions
      // protected function
     }
  ?>

类.Close.php

<?php
 class Close extends CommandBase
 {
    // variables

    // functions

    // public function __construct
 }
?>

类.ATE.php

<?php
class ATE {
    // instance variables

    // public properties

    public function start(){
            $command = new Close();         // class 'Close' not found
    }
    // public function __construct
 }
?>
4

2 回答 2

1

我尝试在 ATE 中同时包含命令库和关闭

This should work, provided 'command base' is include before 'close'.

include ('class.CommandBase.php');
include ('class.Close.php');

and I've tried including just command base in ATE, with close in command base

'close' in 'command base' won't work, since 'close' extends 'command base'.

Ideally, I would avoid including class files in other class files, and confine my include statements to whatever script is using the classes.

于 2013-09-12T23:29:41.103 回答
0

Class Close 需要包含 Class CommandBase。ATE 类需要包括 Close

类.Close.php

include 'class.CommandBase.php';

类.ATE.php

include 'class.Close.php';

请注意,如果所有文件都在同一个目录中,这将照常工作。如果它们不在同一个目录中,则需要更新它以指向正确的位置。

您还应该查看 PHP 的自动加载类的方法。大帮助!

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

于 2013-09-12T23:26:31.263 回答