【发布时间】:2014-06-20 00:08:02
【问题描述】:
我有一个 Silex 应用程序,可以在本地和服务器上正常工作。只是我的 phpunit 测试在我启动它们时抛出异常(仅在服务器上,本地它们也可以工作):
“不在对象上下文中使用 $this”
我更改了代码,不再缓存防火墙,它工作正常(查看注释部分):
use Silex\Application;
use Silex\ServiceProviderInterface;
class SecurityProvider implements ServiceProviderInterface {
//private $firewall;
public function register(Application $app)
{
$app['firewall'] = $app->protect(function () use ($app) {
// FIXME phpunit tests on server don't like the $this reference (no idea why?)
/*if($this->firewall == null) {
$this->firewall = new Firewall($app);
}
return $this->firewall;*/
return new Firewall($app);
});
}
public function boot(Application $app)
{
}
}
任何人知道为什么我得到了例外?
谢谢大家!
【问题讨论】:
-
函数 () 使用 ($app, $this) { ... } ???
-
你运行的是什么 PHP 版本?根据版本的不同,您可能需要进行不同的调整。
标签: php symfony phpunit this silex