0

I have the following code in Welcome_Controller action_index method:

$route = new Route('(<controller>(/<action>(/<id>)))');
$body = $route->uri(array(
  'controller' => 'welcome',
  'action'     => 'index',
  'id'         => '10'
));
echo Debug::vars($body);

When $route->uri method is called, I am getting an error:

ErrorException [ Fatal Error ]: Function name must be a string in SYSPATH/classes/Kohana/Route.php [ 589 ]

584             }
585 
586             return array($result, $required);
587         };
588 
589         list($uri) = $compile($this->_uri, TRUE);
590 
591         // Trim all extra slashes from the URI
592         $uri = preg_replace('#//+#', '/', rtrim($uri, '/'));
593 
594         if ($this->is_external())

Why am I getting this error? According to Kohana install.php file, my environment passed all requirements.

$compile is an anonymous function, but according to PHP Manual there were introduced in PHP 5.3.0 version, which I have on my hosting environment. Maybe there is an option to enable/disable anonymous functions in PHP?

You can find whole code here: https://github.com/DamianKedzior/kohana/tree/3.3/route_uri_exception

  • Where you define `$compile`? – fusion3k Apr 03 '16 at 10:25
  • In [Kohana/Route.php](https://github.com/kohana/core/blob/3.3/master/classes/Kohana/Route.php). It is a part of Kohana core. – Damian Kędzior Apr 04 '16 at 07:01
  • I have deployed this solution to two different hosting environments. It was working on one of them. Strange thing is that both of them have PHP version > 5.3.0 which is required for anonymous functions in PHP. On not working environment I have changed from PHP 5.4.x to PHP 5.5.x and it starts to work. Still don't know why and what is the difference between those environments. – Damian Kędzior Apr 04 '16 at 07:17

0 Answers0