We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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...



18.4k
Accepted
answer
edited Mar '14

Coz:

$className = 'App\CI\SomeClass';


31.8k
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).