Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Call to undefined function

Tags:

function

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?

like image 425
janenz00 Avatar asked Jan 02 '13 01:01

janenz00


People also ask

What does fatal error uncaught error call to undefined function mean?

If you're getting a fatal error notification that begins with the following description “Uncaught Error: Call to undefined function ctype_xdigit()” , that means that the ctype_xdigit function is missing from PHP version installed on your hosting.

What does call undefined mean?

It means exactly what it says. You are using a function the software has no knowledge of. If you had copy pasted the function in Google you would have found more than a few topics on this. One of them being this one stackoverflow.com/questions/3682615/….

What is the PHP Fatal Error type?

Fatal Error There are three (3) types of fatal errors: Startup fatal error (when the system can't run the code at installation) Compile time fatal error (when a programmer tries to use nonexistent data) Runtime fatal error (happens while the program is running, causing the code to stop working completely)


1 Answers

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.

like image 61
Eric Leschinski Avatar answered Sep 29 '22 08:09

Eric Leschinski