1 | <?php |
||
12 | class HtmlNode extends ArrayNode |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Remembers what the innerHtml was if it was scanned previously. |
||
17 | */ |
||
18 | protected $innerHtml = null; |
||
19 | |||
20 | /** |
||
21 | * Remembers what the outerHtml was if it was scanned previously. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $outerHtml = null; |
||
26 | |||
27 | /** |
||
28 | * Remembers what the text was if it was scanned previously. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $text = null; |
||
33 | |||
34 | /** |
||
35 | * Remembers what the text was when we looked into all our |
||
36 | * children nodes. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $textWithChildren = null; |
||
41 | |||
42 | /** |
||
43 | * Sets up the tag of this node. |
||
44 | * |
||
45 | * @param $tag |
||
46 | */ |
||
47 | public function __construct($tag) |
||
55 | |||
56 | /** |
||
57 | * Gets the inner html of this node. |
||
58 | * |
||
59 | * @return string |
||
60 | * @throws UnknownChildTypeException |
||
61 | */ |
||
62 | public function innerHtml() |
||
100 | |||
101 | /** |
||
102 | * Gets the html of this node, including it's own |
||
103 | * tag. |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | public function outerHtml() |
||
136 | |||
137 | /** |
||
138 | * Gets the text of this node (if there is any text). Or get all the text |
||
139 | * in this node, including children. |
||
140 | * |
||
141 | * @param bool $lookInChildren |
||
142 | * @return string |
||
143 | */ |
||
144 | public function text($lookInChildren = false) |
||
179 | |||
180 | /** |
||
181 | * Call this when something in the node tree has changed. Like a child has been added |
||
182 | * or a parent has been changed. |
||
183 | */ |
||
184 | protected function clear() |
||
190 | |||
191 | /** |
||
192 | * Returns all children of this html node. |
||
193 | * |
||
194 | * @return array |
||
195 | */ |
||
196 | protected function getIteratorArray() |
||
200 | } |
||
201 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.