We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.5k
Accepted
answer
edited Mar '14

Coz:

$className = 'App\CI\SomeClass';


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