How to reproduce the error, and how to fix it:

  1. Put this code in a file called p.php:

    <?php
    class yoyo{
        function salt(){
        }
        function pepper(){
            salt();
        }
    }
    $y = new yoyo();
    $y->pepper();
    ?>
    
  2. Run it like this:

    php p.php
    
  3. We get error:

    PHP Fatal error:  Call to undefined function salt() in 
    /home/el/foo/p.php on line 6
    
  4. Solution: use $this->salt(); instead of salt();

    So do it like this instead:

    <?php
    class yoyo{
        function salt(){
        }
        function pepper(){
            $this->salt();
        }
    }
    $y = new yoyo();
    $y->pepper();
    
    ?>
    

If someone could post a link to why $this has to be used before PHP functions within classes, yeah, that would be great.

Answer from Eric Leschinski on Stack Overflow
🌐
Exakat
php-errors.readthedocs.io › en › latest › messages › call-to-undefined-function.html
Call to undefined function — PHP error messages 1.0 documentation
February 21, 2025 - Its existence may be checked with a call to get_defined_function(), which lists all the functions, at the execution point. A function may be disabled in the PHP.ini, using the disabled_functions directive.
🌐
PHP.Watch
php.watch › versions › 8.4 › array_find-array_find_key-array_any-array_all
New `array_find`, `array_find_key`, `array_any`, and `array_all` functions - PHP 8.4 • PHP.Watch
Returns NULL if no matching element is * found. * * @param array $array The array that should be searched. * @param callable $callback The callback function to call to check * each element. The first parameter contains the value ($value), * the second parameter contains the corresponding key ($key).
Top answer
1 of 8
95

How to reproduce the error, and how to fix it:

  1. Put this code in a file called p.php:

    <?php
    class yoyo{
        function salt(){
        }
        function pepper(){
            salt();
        }
    }
    $y = new yoyo();
    $y->pepper();
    ?>
    
  2. Run it like this:

    php p.php
    
  3. We get error:

    PHP Fatal error:  Call to undefined function salt() in 
    /home/el/foo/p.php on line 6
    
  4. Solution: use $this->salt(); instead of salt();

    So do it like this instead:

    <?php
    class yoyo{
        function salt(){
        }
        function pepper(){
            $this->salt();
        }
    }
    $y = new yoyo();
    $y->pepper();
    
    ?>
    

If someone could post a link to why $this has to be used before PHP functions within classes, yeah, that would be great.

2 of 8
30

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
php.net › manual › en › function.array-find.php
PHP: array_find - Manual
array_find() returns the value of the first element of an array for which the given callback returns true. If no matching element is found the function returns null.
🌐
PHP
wiki.php.net › rfc › array_find
PHP: rfc:array_find
This RFC proposes to add four new function, array_find, array_find_key, array_any and array_all. array_find returns the value of the first element for which the $callback returns true.
🌐
PHPBuilder
board.phpbuilder.com › d › 10304116-resolved-fatal-error-call-to-undefined-function-array
[RESOLVED] Fatal error: Call to undefined function: array() - PHPBuilder Forums
July 10, 2005 - Here is the full error message: Fatal error: Call to undefined function: array() in /www/www.sailinganarchy.com/htdocs/classified/ad_display.php on line 40...
🌐
SitePoint
sitepoint.com › php
How to resolve call to undefined function? - PHP - SitePoint Forums | Web Development & Design Community
April 17, 2024 - How to resolve call to undefined function · Hi, was hoping that someone here could help me resolve this error: production.ERROR: Call to undefined function App\Services\addAsset() {“userId”:3,“exception”:"[object] (Error(code: 0): Call to undefined function App\Services\addAsset() ...
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 59905396 › call-to-undefined-function-in-array
php - Call to undefined function in Array - Stack Overflow
i have a Problem with my PHP Code. I get an "Fatal error: Call to undefined function fabo_autor()" Error on the following Code (Line 2): $message = show(settings('eml_fabo_npost'), array("nick" => re($getabo['nick']), "postuser" => fabo_autor($userid), "topic" => $gettopic['topic'], "titel" => $title, "domain" => $httphost, "id" => intval($_GET['id']), "entrys" => $entrys+1, "page" => $pagenr, "text" => bbcode($_POST['eintrag']),; Would be great if someone could help me out here.
🌐
PHP Freaks
forums.phpfreaks.com › php coding › php coding help
[SOLVED] Hey Guys, Call to undefined function: array() Prob ..... - PHP Coding Help - PHP Freaks
February 10, 2008 - Greetings Guys, New to php and having a little problem with a script im working on, i recieve the error, Fatal error: Call to undefined function: array() in /usr/home/web/users/a0028977/html/const/temp/login.php on line 7 Originally i thought it was a synax error but after a few hours of checking...
🌐
GitHub
github.com › laravel › framework › issues › 56870
The array_first helper function breaks in PHP =
September 2, 2025 - This fix uses the function array_find_key, which was introduced in PHP 8.4. This results in an Call to undefined function array_find_key error on our systems which are still running on 8.3.
Published   Sep 02, 2025
🌐
Delft Stack
delftstack.com › home › howto › php › php call to undefined function
How to Call to Undefined Function in PHP | Delft Stack
February 2, 2024 - Such a thing is beneficial because it allows you to access all the member variables and methods of the class. Inside the class, it is called $this->functionName(). Outside of the class, it is called $theclass->functionName(). $this is a reference to a PHP object the interpreter created for you, which contains an array of variables.
🌐
Roots Discourse
discourse.roots.io › sage
PHP Fatal error: Call to undefined function array_except() - sage - Roots Discourse
February 13, 2021 - Hello I have just build a theme and trying to FTP move on staging. I keep receiving this error: PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined function array_excep…
🌐
3v4l
3v4l.org › jE4IU
Online PHP editor | output for jE4IU
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) Process exited with code 1. Output for 8.1.32 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.29 · Fatal error: Uncaught Error: Call to undefined function array_find() in /in/jE4IU:10 Stack trace: #0 {main} thrown in /in/jE4IU on line 10 Process exited with code 255.
🌐
GitHub
github.com › troydavisson › PHRETS › issues › 247
Fatal error: Uncaught Error: Call to undefined function array_get() · Issue #247 · troydavisson/PHRETS
July 28, 2019 - "Fatal error: Uncaught Error: Call to undefined function array_get() in /.../vendor/troydavisson/phrets/src/Models/Metadata/Base.php:50 Stack trace: #0 /.../cronTask/mls_rets_egyp.php(46): PHRETS\Models\Metadata\Base->__call('getsystemdescri...', Array) #1 {main} thrown in /.../vendor/troydavisson/phrets/src/Models/Metadata/Base.php on line 50" My environment is the following: nginx server, ubuntu, php 7.2.19, phrets 2.6 The error looks like is in one of the dependency installed "illuminate" there is the method "array_get" and for reason phrets can't see it.
Published   Sep 19, 2019
🌐
Reddit
reddit.com › r/phphelp › uncaught error: call to undefined function (i cannot call a function that is in the same php file)
r/PHPhelp on Reddit: Uncaught Error: Call to undefined function (I cannot call a function that is in the same php file)
December 27, 2021 -

Hello i have this issue but im not figured out why

i have this in cart.php

  function deleteCart($id){
        foreach($_SESSION["cart"] as $keys => $values)   {  
            if($values["item_id"] == $_GET["skuid"]) {  
                unset($_SESSION["cart"][$keys]);  
                echo"Item Removed";  
                
            }  
            
        }  
    }

and in the sime file i have

function buyCart(){
code....
    if( $row==0){
    code...
    }else{
     $id=1;
    deleteCart($id);
    }
}

why???

🌐
PHP Freaks
forums.phpfreaks.com › php coding › php coding help
[SOLVED] Call to undefined function inarray() - PHP Coding Help - PHP Freaks
December 26, 2008 - Does anyone know why this wont work? When there is not act being called (so no act passed in the URL) it works fine, but as soon as you click an option and an act gets passed in the URL i get that error and i cant seem to figure out why.