Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Call to undefined method" - but I know it exists

Tags:

php

This line of code:

echo "<strong> {$this->author->last} {$this->date->shortYear()}</strong> ...";

gives me this error:

Fatal error: Call to undefined method Date::shortYear() in /f5/debate/public/libs/Card.php  on line 22

Even though in Date.php (which is included in Card.php):

class Date {
    public $day;
    public $month;
    public $year;

    public function shortYear() {
        return substr($this->year, -2);
    }
}
like image 295
cactusbin Avatar asked Oct 17 '25 12:10

cactusbin


2 Answers

You're instantiating the wrong Date class. You can use PHP's get_class_methods() function to confirm which methods are available.

like image 129
Chris Hallett Avatar answered Oct 19 '25 01:10

Chris Hallett


If you work in an setup where you automatically upload your changes from your IDE to the web server your checking your pages on. It might accidentally be the case that it didn't upload the file.

like image 39
Erik vd H Avatar answered Oct 19 '25 01:10

Erik vd H