普通网友 2014-06-27 05:17
浏览 83

PHP - symfony2 - 检查Session是否设置时出错

Problem - I want to check whether the session is set or not in the '__construct' of a 'Controller', but i am getting the following error -

FatalErrorException: Compile Error: Cannot use isset() on the result of a function call (you can use "null !== func()" instead)

The following is the code snippet which is in my '__construct' -

function __construct() {

   $request = Request::createFromGlobals();
   $session = $request->getSession();
   if(!isset($session->get('id'))){
     $this->redirect('UserAuthBundle:Auth:login.html.twig');
   }

}

If I use '!= null' instead of '!isset' its giving me an error as following -

FatalErrorException: Error: Call to a member function get() on a non-object

Is there any other alternative way so that this can be implemented.

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • douzhai7873 2014-06-27 05:21
    关注

    Manual says:

    Warning

    isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.

    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示