The return type of return $result; (ArrayList) is incompatible with the return type declared by the interface SeoInformationProvider::getImagesForSeo of type DataList.
If you return a value from a function or method, it should be a sub-type of the
type that is given by the parent type f.e. an interface, or abstract method.
This is more formally defined by the
Lizkov substitution principle,
and guarantees that classes that depend on the parent type can use any instance
of a child type interchangably. This principle also belongs to the
SOLID principles
for object oriented design.
Our function my_function expects a Post object, and outputs the author
of the post. The base class Post returns a simple string and outputting a
simple string will work just fine. However, the child class BlogPost which
is a sub-type of Post instead decided to return an object, and is
therefore violating the SOLID principles. If a BlogPost were passed to
my_function, PHP would not complain, but ultimately fail when executing the
strtoupper call in its body.
Loading history...
21
}
22
23
24
public function getLinksForSeo() {
25
return false;
26
}
27
28
}
29
30
class PageWithImageFolder_Controller extends PageWithImage_Controller {
PSR1 recommends that each class should be in its own file to aid autoloaders.
Having each class in a dedicated file usually plays nice with PSR autoloaders
and is therefore a well established practice. If you use other autoloaders, you
might not want to follow this rule.
In camelCase names are written without any punctuation, the start of each new word
being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes DatabaseProvider.
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.