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:
I am not able to figure this out. Am I missing something here?
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
Put this code in a file called p.php
:
<?php
class yoyo{
function salt(){
}
function pepper(){
salt();
}
}
$y = new yoyo();
$y->pepper();
?>
Run it like this:
php p.php
We get error:
PHP Fatal error: Call to undefined function salt() in
/home/el/foo/p.php on line 6
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.
Source: Stackoverflow.com