4

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?

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
jasonmoqio
  • 189
  • 1
  • 2
  • 15

1 Answers1

11

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

Community
  • 1
  • 1
isuruAb
  • 2,202
  • 5
  • 26
  • 39