I’m quite new to PHP and Namespacing. I’m trying to use cakePHP to develop a website and i’m stuck with a problem regarding the use of a function imported from a different namespace.
the problem is the following:
I’ve defined a Class inside a proper namespace called AppPlanner.
The class file is also called Planner.php and it’s locate under src/Planner/Planner.php
<?php
namespace AppPlanner;
class Planner
{
public static function myfunc(){}
}
Then I’ve got my controller called ChallengesControllerdefined as a class inside a file also called ChallengesController.php under src/Controller/ChallengesController.php which has it’s own namespace AppController. Here I’ve done the following:
<?php
declare(strict_types=1);
namespace AppController;
\ some more imports
use AppPlannerPlanner;
class ChallengesController extends AppController
{
public function doThings(){
$res = Planner::myfunc();
}
}
Now when i call the endpoint /challenges/doThings it reaches the line when i call the function but then gives the following error (i’m using Xdebug to debug):
message = "Call to undefined function AppPlannerknapSolveFast2()"
file = "/var/www/myapp/src/Planner/Planner.php"
my composer.json autoload is set as follow:
"autoload": {
"psr-4": {
"App\": "src/"
}
},
can anybody explain to me what i’m missing?
thanks