Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Why the class not found

Just look like below:

=======SomeClass.php:==========

namespace App\Cl;

class SomeClass {}

==========MainClass.php===========

namespace App\Cl;

$className = 'SomeClass';

$class = new $className(); // SomeClass Not found

$class = new SomeClass(); // here is correct

Why above two line is different...



12.3k
Accepted
answer
edited Mar '14

Coz:

$className = 'App\CI\SomeClass';


16.9k
edited Mar '14

Thank you so much! Can you explain two class in same namespace, Why still need 'App\CI\' ? I want to know the reason...

Coz php interprets variable with class without context (so it doesn't know what is current namespace).