PHP调用未定义的函数 [英] PHP Call to undefined function

查看:1163
本文介绍了PHP调用未定义的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从另一个函数调用一个函数。我收到一个错误:

 致命错误:调用未定义的函数getInitialInformation()
在第24行的controller.php中

controller.php文件:

  require_once(model / model.php); 

函数摄入量(){
$ info = getInitialInformation($ id); // line 24
}

model / model.php


$ b $ pre $ 函数getInitialInformation($ id){
return $ GLOBALS ['em'] - > find('InitialInformation ',$ id);
}

已经试过的东西:


  • 确认require_once有效,并且文件存在于指定的位置。

  • 验证函数是否存在于文件中。 b $ b

    我无法弄清楚。我在这里错过了什么?

    解决方案

    这是一个开发人员的错误 - 错位的结束括号, >嵌套函数。



    我看到很多与SO中未定义函数错误有关的问题。让我记下这个答案,以防其他人与函数作用域有相同的问题。



    我试图首先排除故障:


    1. 搜索php文件其中的函数定义。验证文件是否存在。

    2. 验证上述文件的需要(或 include )语句存在于页面中。此外,验证了 require / include 中的绝对路径是正确的。

    3. 验证文件名在require语句中拼写正确。

    4. 在包含的文件中回复一个单词,以查看它是否已被正确包含。<​​/ li>
    5. 在文件末尾定义一个单独的函数,然后调用它。它也起作用。

    很难追溯大括号,因为功能非常长 - 遗留系统存在问题。进一步的故障排除步骤如下:


    1. 我已经在包含文件的末尾定义了一个简单的打印功能。我将它移动到未定义函数之上。这也使得它也不明确。

    2. 确定这是一个范围问题。

    3. 使用Netbeans折叠(代码折叠)功能来检查在这个之上的功能。因此,上面的1000行函数与这个函数一起折叠,这使得它成为一个嵌套函数。
    4. 一旦确定问题,将函数剪切粘贴到解决了问题。



    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?

    解决方案

    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.

    这篇关于PHP调用未定义的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆