Problems with callback and namespaces
Opened this issue · 1 comments
ecow commented
Hi,
I got a strange problem that I can't understand. This snippet:
<?php
namespace test;
require 'vendor/autoload.php';
use Respect\Rest\Router;
$r3 = new Router('/tools/test.php');
$r3->get('/', function() {
return array('v' => 2.0);
})->accept( array( 'text/html' => array( 'myns\\Standard', 'htmlRenderer')));
namespace myns;
class Standard
{
public static function htmlRenderer($data)
{
return 'OK';
}
}
works on window with php 5.4 and fails (Fatal error: Function name must be a string ) in ubuntu with php 5.3.
If in ubuntu I change the line 67 in file request.php from:
$response = $proxyCallback($response);
to
$response = call_user_func($proxyCallback,$response);
it works!
The problem seams related to namespace because if I remove namespace it works in both environments.
Can someone figure why?
This is a great library!!! Thank you
UPDATE:
It seams that the problem is related to a change in php 5.4.:
$callback = array($object, 'methodName');
$callback(); // prior to PHP 5.4 you need call_user_func()
Is php 5.4 a requirement for Respect\Rest?