Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Uncaught Error: Call to undefined function - have to use $this

Here is my code:

<?php

public function __construct() {
    getUsername();
}

public function getUsername() {
    //blah blah blah

    return "bobby";
}

?>

It does not work and it says this error:

Fatal error: Uncaught Error: Call to undefined function...

but if I call the function in my constructor like this: $this->getUsername(); it works. Why is that the case?

like image 547
jasonmoqio Avatar asked Dec 18 '22 09:12

jasonmoqio


1 Answers

It cannot identify your method. We have to tell it to use getUsername() method which is in this class like this $this->getUsername(); $this-> is for find in this class. read this link

like image 67
isuruAb Avatar answered May 02 '23 15:05

isuruAb