1 | <?php |
||
16 | class HtmlButtonGroups extends HtmlSemCollection { |
||
17 | protected $_dropdown; |
||
18 | public function __construct($identifier, $elements=array(), $asIcons=false) { |
||
27 | |||
28 | public function addDropdown($items,$asCombo=false){ |
||
38 | |||
39 | |||
40 | public function addElement($element, $asIcon=false) { |
||
46 | |||
47 | public function addElements($elements, $asIcons=false) { |
||
53 | |||
54 | public function insertOr($aferIndex=0, $or="or") { |
||
60 | |||
61 | /* |
||
62 | * (non-PHPdoc) |
||
63 | * @see \Ajax\bootstrap\html\HtmlSingleElement::fromArray() |
||
64 | */ |
||
65 | public function fromArray($array) { |
||
68 | |||
69 | public function asIcons() { |
||
76 | |||
77 | public function setVertical() { |
||
80 | |||
81 | public function setLabeled() { |
||
84 | |||
85 | /** |
||
86 | * Return the element at index |
||
87 | * @param int $index |
||
88 | * @return HtmlButton |
||
89 | */ |
||
90 | public function getElement($index) { |
||
93 | |||
94 | public function setElement($index, $button) { |
||
98 | |||
99 | /* |
||
100 | * (non-PHPdoc) |
||
101 | * @see \Ajax\bootstrap\html\base\BaseHtml::on() |
||
102 | */ |
||
103 | public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
||
109 | |||
110 | public function getElements() { |
||
113 | |||
114 | public function addClasses($classes=array()) { |
||
124 | |||
125 | /* |
||
126 | * (non-PHPdoc) |
||
127 | * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject() |
||
128 | */ |
||
129 | public function fromDatabaseObject($object, $function) { |
||
132 | |||
133 | public function run(JsUtils $js){ |
||
137 | |||
138 | public function getDropdown() { |
||
141 | |||
142 | } |
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.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.