Answer the question
In order to leave comments, you need to log in
Why is the class not visible when using a namespace alias?
Hello.
File structure:
- App
-- ctrls
--- MyClass.php
- index.php
MyClass.php code:
<?php
namespace App\ctrls;
class MyClass{
public $str = 'test';
public static function getMe()
{
echo 'My namespace App. My name is getMe()';
}
}
?>
<?php
require "App/ctrls/MyClass.php";
App\ctrls\MyClass::getMe();
?>
<?php
use App\ctrls as path;
$o = new path\MyClass.php;
?>
Answer the question
In order to leave comments, you need to log in
read about autoloading
https://github.com/codedokode/pasta/blob/master/ph...
in particular, about PSR-4
install the composer, if it's not worth
in the root of your project, create a file composer.json with content
{
"autoload": {
"psr-4": {
"App\\": "App"
}
}
}
composer install
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question