I have the following class
<?php
namespace Core;
class Router
{
public $routes = [
[
'url' => '/register',
'controller' => BASE_PATH . 'controllers/registration/register.get.php',
'method' => 'GET',
'middleware' => fn() => true,
]
];
public function route()
{
//...
}
}
When I add that middleware key that points to a function, I get the Fatal error: Constant expression contains invalid operations. What I am trying to do is simply create the router, call its route method, and then depending on the current route call the middleware function. What is the right syntax for this sort of thing in PHP?