duanjizhan9353 2013-01-02 01:20
浏览 357
已采纳

PHP调用未定义的函数

I am trying to call a function from another function. I get an error:

Fatal error: Call to undefined function getInitialInformation() 
in controller.php on line 24

controller.php file:

require_once("model/model.php"); 

function intake() {
    $info = getInitialInformation($id); //line 24
}

model/model.php

function getInitialInformation($id) {
    return $GLOBALS['em']->find('InitialInformation', $id);
}

Things already tried:

  1. Verified that the require_once works, and the file exists in the specified location.
  2. Verified that the function exists in the file.

I am not able to figure this out. Am I missing something here?

  • 写回答

6条回答 默认 最新

  • duanliang9288 2013-01-02 02:04
    关注

    This was a developer mistake - a misplaced ending brace, which made the above function a nested function.

    I see a lot of questions related to the undefined function error in SO. Let me note down this as an answer, in case someone else have the same issue with function scope.

    Things I tried to troubleshoot first:

    1. Searched for the php file with the function definition in it. Verified that the file exists.
    2. Verified that the require (or include) statement for the above file exists in the page. Also, verified the absolute path in the require/include is correct.
    3. Verified that the filename is spelled correctly in the require statement.
    4. Echoed a word in the included file, to see if it has been properly included.
    5. Defined a separate function at the end of file, and called it. It worked too.

    It was difficult to trace the braces, since the functions were very long - problem with legacy systems. Further steps to troubleshoot were this:

    1. I already defined a simple print function at the end of included file. I moved it to just above the "undefined function". That made it undefined too.
    2. Identified this as some scope issue.

    3. Used the Netbeans collapse (code fold) feature to check the function just above this one. So, the 1000 lines function above just collapsed along with this one, making this a nested function.

    4. Once the problem identified, cut-pasted the function to the end of file, which solved the issue.

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题