[php] PHP Call to undefined function

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 question is related to php function

The answer is


Many times the problem comes because php does not support short open tags in php.ini file, i.e:

<?
   phpinfo();
?>

You must use:

<?php
   phpinfo();
?>

I happened that problem on a virtual server, when everything worked correctly on other hosting. After several modifications I realized that I include or require_one works on all calls except in a file. The problem of this file was the code < ?php ? > At the beginning and end of the text. It was a script that was only < ?, and in that version of apache that was running did not work


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.


Please check that you have <?PHP at the top of your code. If you forget it, this error will appear.


Presently I am working on web services where my function is defined and it was throwing an error undefined function.I just added this in autoload.php in codeigniter

$autoload['helper'] = array('common','security','url');

common is the name of my controller.


Your function is probably in a different namespace than the one you're calling it from.

http://php.net/manual/en/language.namespaces.basics.php