1

Let's say that we have a file named "include.php" in a directory, "includes", and this file includes another file, "manager.php", from a sub directory, "objects",

include "objects/manager.php";

now "manager.php" is a class names "manager" that has a function that does an include:

public function includeDBObject()
{
    include "databaseobjects/mysql.php";
} 

This include is another class, "mysql class", that has the following contents:

public $name = "I am in the MySql class";

public function getName()
{
    return $this->name;
}

Now back to the original include, "include.php", the contents are as follows

include "objects/manager.php";//as shown above

$a = new manager;
$a->includeDBObject();
$b = new mysql;
echo $b->getName();

The result of this is: "I am in the MySql class."

Shouldn't the $a->includeDBObject trigger an error of not being able to find the file as the specified directory is incorrect with relation to where "include.php" is located?

According to the php documentation the include does: "The include statement includes and evaluates the specified file."

http://php.net/manual/en/function.include.php

so since manager.php is included the directory in its include function should throw an error as it is "included" in a different directory.

Any explanation would help with references to documentation.

Thanks

Robert
  • 10,126
  • 19
  • 78
  • 130
  • `include` does not care about classes or objects. And neither do the instantiated objects where their definition resided. All include scripts were found, executed, and the outcome is as to be expected. – mario Aug 13 '13 at 21:14
  • My question is more of a directory retrieval one. – Robert Aug 13 '13 at 21:17
  • Then why did you mention objects in the title, and put all that irrelevant object code in the question. All you needed were the include lines. – Barmar Aug 13 '13 at 21:19
  • [This answer](http://stackoverflow.com/a/17627419/2364629) should clue you in on what is happening. – Orangepill Aug 13 '13 at 22:24

0 Answers0