Struttura:
/app/boostrap.php
/libs/View.php
/libs/helpers/FormHelper.php
/test.php
Codice PHP:
// /app/bootstrap.php
spl_autoload_register(function ($class){
require_once(dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php');
});
Codice PHP:
// /libs/helpers/FormHelper.php
namespace libs\helpers;
class FormHelper {
public function __construct() {
echo(__METHOD__);
}
}
Codice PHP:
// /libs/View.php
namespace libs;
use libs\helpers\FormHelper;
class View {
public function __construct() {
$helper = new FormHelper();
}
}
Codice PHP:
// /test.php use libs\View;
require_once(__DIR__ . '/app/bootstrap.php');
$view = new View;
Testato e funzionante.