douna4762 2015-01-01 15:06
浏览 82
已采纳

sym2 IF语句给出错误“调用未定义的函数”

I have an issue with my IF-statement, apparently.

Inside a symfony2 controller I have the following PHP:

57   foreach($all as $t) {
58       if ( ($end == null) || ($t->getDate()->format('Y-m-d') <= $end->format("Y-m-d")) ) {
59           if ( ($start == null) || ($t->getDate()->format('Y-m-d') >= $start->format("Y-m-d")) ) {
60              $subset[] = $t;
61          }
62      }
63   }

I get this for an error message:

FatalErrorException: Error: Call to undefined function App\Bundle\Controller\ () in 
www/App/src/App/Bundle/Controller/TransactionController.php line 59

If I comment the second IF-statement out like this, it runs without errors.

foreach($all as $t) {
    if ( ($end == null) || ($t->getDate()->format('Y-m-d') <= $end->format("Y-m-d")) ) {
        /*
        if ( ($start == null) || ($t->getDate()->format('Y-m-d') >= $start->format("Y-m-d")) ) {    
            $subset[] = $t;
        }
        */
    }
}

So somewhere in my if statement it tries to run a sym2 controller? I am lost...

Both $start and $end are valid DateTime objects, so are each $date on the $t objects.

If I var_dump the variables just before the second if-condition they print:

start: object(DateTime)#1149 (3) { ["date"]=> string(19) "2014-12-20 16:39:06" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" }

end: object(DateTime)#1150 (3) { ["date"]=> string(19) "2015-01-19 16:39:06" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" }

t->getDate(): object(DateTime)#1046 (3) { ["date"]=> string(19) "2012-12-11 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" }

  • 写回答

2条回答 默认 最新

  • dosrmo0442 2015-01-01 19:04
    关注

    The error itself looks suspicious, with that whitespace between the namespace and parentheses:

    Call to undefined function App\Bundle\Controller\ ()
    

    Normally you'd expect to see something like:

    Call to undefined function App\Bundle\Controller\foo_function()
    

    Whatever is going on, PHP is seeing a "function" with a "blank" name. I have encountered weird situations like this before, when I type really fast and happen to press a control character while inserting text. It often happens around a space character, because on my keyboard the control character is next to the space bar.

    Reproducing it will be next to impossible. The best thing to do is just delete the line and retype it again, slowly.

    If you're hell-bent on diagnosing it, then on GNU/Linux you can "take the cat to the vet":

    $ cat file.php
    <?php if (1 == 1) echo 'hi';
    
    $ cat -vet file.php
    <?php if (1 == ^@1) echo 'hi';
    

    I used my editor to insert a null-byte in the if statement, which doesn't appear in normal inspection but does show when given to "the vet".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥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 没法显示