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 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红