Question

Where do I put includes to get the close to properly register? I have tried including both command base and close in ATE, and I've tried including just command base in ATE, with close in command base... no matter what I do, it says Close not found.

class.CommandBase.php

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

class.Close.php

<?php
 class Close extends CommandBase
 {
    // variables

    // functions

    // public function __construct
 }
?>

class.ATE.php

<?php
class ATE {
    // instance variables

    // public properties

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

Solution

I have tried including both command base and close in 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.

OTHER TIPS

Class Close needs to include Class CommandBase. Class ATE needs to include Close

class.Close.php

include 'class.CommandBase.php';

class.ATE.php

include 'class.Close.php';

Be aware that this will work as is IF all the files are in the same directory. If they are NOT in the same directory you will need to update this to point to the right location.

You also should look at PHP's method for autoloading classes. BIG help!

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top