I have a problem with including classes. Here's a simple example to explain the problem:
Class no. 1 (path: /home/day/Class_A.php):
class Class_A {
public function sayHi() {
echo "Good day";
}
}
Class no. 2 (path: /home/test/Class_B.php):
class Class_B {
public function greeting() {
if(class_exists("Class_A")!=true)
include "../day/Class_A.php";
$test = new Class_A();
$test->sayHi();
}
}
PHP file (path: /home/php.php)
if(class_exists("Class_B")!=true)
include "test/Class_B.php";
$g = new Class_B;
$g->greeting();
The problem is when php.php includes Class_B and Class_B includes Class_A, Class_B fails to open Class_B because the path of the object of the class is now the same as the php.php file.
My question is: Is there a good and simple way to get around this?