简体   繁体   中英

Call to undefined method in class even when it is defined

I am getting the following error message turning up in my apache error logs:

PHP Fatal error: Call to undefined method MyWebsite\\Model\\ContentMedia::getImagePath() in /var/www/www.website.com/application/libraries/MyWebsite/Model/ContentVersion.php on line 544

On line 544 of ContentVersion.php the call is made:

$cm->getImagePath('img', 'small');

The ContentMedia class extends another class called Model that does have that method:

class ContentMedia extends \MyWebsite\Model{

... the Model class:

namespace MyWebsite;

class Model{

    public function getImagePath($field, $size = null){

        ...
    }

I get this error show up every now and then in the log files, so it may be one particular instance where a user comes across this, but I don't know where. This method is used throughout the site and it works. If the method is definitely defined how can this error be thrown?

I thought about checking the access logs to match an exact requested URL to the timestamp of the error, but the access logs are insanely large of course, so any advice as to how to output just a chunk of time from a large access log would be amazing.

I am using Doctrine 2 and Codeigniter 2.

My first thought is to check that you definitely have an instance of model present within the script. Have you tried creating another function for the sake of testing that will just echo something like "Object is instantiated and inherited functions properly".

That way we might be able to narrow down the problem a little

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM