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条)

报告相同问题?

悬赏问题

  • ¥20 数学建模数学建模需要
  • ¥15 c语言数据结构实验单链表的删除
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决