I have made my own php mini-framework and my index.php looks something like this
<?php
require __DIR__.'/../app/autoloader.php';
Autoloader::register();
use Stories\http\routing\{RouteCollection,Matcher,Route};
use Stories\http\Request;
use Stories\App\Stories;
$app = new Stories();
$routes = new RouteCollection();
$home = new Route('/',function(Request $request) use ($app) {
return \Stories\Processor::home($request,$app);
}, ['method' => 'GET']);
$routes->add("home",$home);
...
$login = new Route('/login', function (Request $request) use ($app) {
return \Stories\Processor::login($request,$app);
}, ['method' => 'GET']);
$routes->add('login',$login);
$matcher = new Matcher($routes);
$matcher->find()->run();
However, some people told me that making an instance of \my\namespace\processor and passing it to the function like this :
<?php
require __DIR__.'/../app/autoloader.php';
Autoloader::register();
use Stories\http\routing\{RouteCollection,Matcher,Route};
use Stories\http\Request;
use Stories\App\Stories;
use Stories\Processor;
$app = new Stories();
$routes = new RouteCollection();
$processor = new Processor();
$home = new Route('/',function(Request $request) use ($app,$processor) {
return $processor->home($request,$app);
}, ['method' => 'GET']);
$routes->add("home",$home);
...
$login = new Route('/login', function (Request $request) use ($app,$processor) {
return $processor->login($request,$app);
}, ['method' => 'GET']);
$routes->add('login',$login);
$matcher = new Matcher($routes);
$matcher->find()->run();
Would be better since the class instance have been created, and I don't know why, my router doesn't run any function but only the one that matches the URI so I don't think it's going to be a problem. I have tested both ways and I don't see any difference.
Since I'm a high school student and the one of the people who told me this is a teacher at a university I though that he may be right, but I don't see any difference in memory usage.
Update
Based on @smuuf's answer, I want to say that processor is not a proper class, instead of writing 10 or 20 lines of code inside every function in index.php calling other classes like view,users,orm... etc, I made the processor class with static methods that does exactly the same, the processor class doesn't use any of its own methods or properties while processing the request.
Update 2
I just updated my router and I also updated the code to look exactly like my index.php but I'm still looking for answer for the same question.