Reputation: 99
I am getting an error in PHP:
PHP Fatal error: Call to undefined function getCookie
Code:
include('Core/dAmnPHP.php');
$tokenarray = getCookie($username, $password);
Inside of dAmnPHP.php, it includes a function called getCookie inside class dAmnPHP. When I run my script it tells me that the function is undefined.
What am I doing wrong?
Upvotes: 6
Views: 47831
Reputation: 153882
How to reproduce this error:
Put this in a file called a.php:
<?php
include('b.php');
umad();
?>
Put this in a file called b.php:
<?php
class myclass{
function umad(){
print "ok";
}
}
?>
Run it:
PHP Fatal error: Call to undefined function umad() in
/home/el/a.php on line 4
What went wrong:
You can't use methods inside classes without instantiating them first. Do it like this:
<?php
include('b.php');
$mad = new myclass;
$mad->umad();
?>
Then the php interpreter can find the method:
eric@dev ~ $ php a.php
ok
Upvotes: 4
Reputation: 586
It looks like you need to create a new instance of the class before you can use its functions.
Try:
$dAmn = new dAmnPHP;
$dAmn->getCookie($username, $password);
I've not used dAmn before, so I can't be sure, but I pulled my info from here: https://github.com/DeathShadow/Contra/blob/master/core/dAmnPHP.php
Upvotes: 9