Answer the question
In order to leave comments, you need to log in
What am I doing wrong that does not find the class through namespace in php?
I declare a class with a namespace
namespace app\models;
class User extends Model {
foo() { }
}
<?php
use app\models\User;
class ControllerComments extends Controller {
User::foo();
}
Class 'app\models\User' not found
Answer the question
In order to leave comments, you need to log in
Do you have autoload configured at least?
Also, your whole code is wrong.
namespace app\models;
class User extends Model {
public static function foo() { echo "I've called by a controller!"; }
}
use \app\models\User;
class ControllerComments extends Controller {
public function __construct() { User::foo(); }
}
$test = new ControllerComments();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question