yiiyii2php-5.6

Non-static method common\components\DirectoryHelpers::mimeType() should not be called statically


totally php newbie here. need help about our library program here. i try to upload our book cover to our webserver, but get this error instead. the problem lines here

the error

got this task to connecting our offline library sytem to webserver ( make it online ) this is what its looks like from the browser browser perspective


Solution

  • The following code:

    $mimetype=DirectoryHelpers::mimeType($files_uploaded);
    

    Change as follows:

    $var = new DirectoryHelpers();
    $mimetype = $var->mimeType($files_uploaded);
    

    Or as a shorthand:

    $mimetype = (new DirectoryHelpers)->mimeType($files_uploaded);
    

    In general: It depends on your needs. If you do not need to instantiate a class, you can change your library function to static. treat static functions like constants, (can not have objects)
    Example here:

    class DirectoryHelpers {
        public static function mimeType() {
            // code ...
        }
    }