I get a fatal error: Fatal error: Class 'Foo1' not found in .../Foo2.php on line 5
with the following files:
index.php:
<?php
require_once("./Foo1.php");
?>
<h1>Success</h1>
Foo1.php:
<?php
require_once('./IFoo.php');
require_once('./Bar.php');
class Foo1 implements IFoo
{
/** @var Bar */
private $bar;
}
IFoo.php:
<?php
interface IFoo {
}
Bar.php:
<?php
require_once('./Foo2.php');
class Bar {
/** @var Foo2 */
private $foo;
}
Foo2.php:
<?php
require_once("./Foo1.php");
class Foo2 extends Foo1
{
}
Questions:
- How to solve this situation?
- Why when I suppress the
implements IFoo
statements, this code works?
Update Most of the solutions proposed, involved autoloading. Unfortunately, my problem is on a old project with a lot of existing code and a lot of bad practice. We are really far from PSR-0 standard.
What is the cost of introducing autoloading in terms of performances?