1 | <?php |
||
19 | class NamedNodelist extends \ArrayObject |
||
20 | { |
||
21 | private $parentNode = null; |
||
22 | |||
23 | public function __construct($list = null, $parentNode = null) |
||
24 | { |
||
25 | parent::__construct( $list ); |
||
26 | $this->parentNode = $parentNode; |
||
27 | } |
||
28 | |||
29 | public function __set($name, $value) |
||
30 | { |
||
31 | switch ($name) { |
||
32 | case 'parentNode': |
||
33 | $this->parentNode = $value; |
||
34 | foreach ($this as $child) { |
||
35 | $child->parentNode = $this->parentNode; |
||
36 | } |
||
37 | break; |
||
38 | } |
||
39 | } |
||
40 | |||
41 | public function __get($name) |
||
49 | |||
50 | public function offsetSet($name, $value) |
||
51 | { |
||
52 | if (!($value instanceof \arc\tree\NamedNode)) { |
||
53 | $value = new \arc\tree\NamedNode( $name, $this->parentNode, null, $value ); |
||
54 | } |
||
55 | $value->parentNode = $this->parentNode; |
||
56 | if ($this->offsetExists( $name )) { |
||
57 | $old = $this->offsetGet( $name ); |
||
58 | if ($old !== $value) { |
||
59 | $old->parentNode = null; |
||
60 | } |
||
61 | } |
||
62 | parent::offsetSet($name, $value); |
||
63 | } |
||
64 | |||
65 | public function offsetUnset($name) |
||
66 | { |
||
67 | if ($this->offsetExists( $name )) { |
||
68 | $node = $this->offsetGet( $name ); |
||
69 | $node->parentNode = null; |
||
70 | } |
||
71 | parent::offsetUnset( $name ); |
||
72 | } |
||
73 | |||
74 | public function __clone() |
||
75 | { |
||
76 | $this->parentNode = null; |
||
77 | foreach ((array) $this as $name => $child) { |
||
78 | $clone = clone $child; |
||
79 | $clone->parentNode = $this->parentNode; |
||
80 | parent::offsetSet( $name, $clone ); |
||
|
|||
81 | } |
||
82 | } |
||
83 | |||
84 | public function exchangeArray($input) |
||
94 | } |
||
95 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.