Skip to content

Commit 8c80c20

Browse files
authored
Fix hooks example (#4392)
1 parent c39225b commit 8c80c20

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

language/oop5/property-hooks.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,10 @@ class PositivePoint extends Point
498498
Hooks may not access any other hook except their own parent on their own property.
499499
</simpara>
500500
<simpara>
501-
The example above could be rewritten more efficiently as follows.
501+
The example above could be rewritten as follows, which would allow for the
502+
<literal>Point</literal> class to add its own <literal>set</literal> hook
503+
in the future without issue. (In the previous example, a hook added to
504+
the parent class would be ignored in the child.)
502505
</simpara>
503506
<example>
504507
<title>Parent hook access (set)</title>
@@ -518,7 +521,7 @@ class PositivePoint extends Point
518521
if ($value < 0) {
519522
throw new \InvalidArgumentException('Too small');
520523
}
521-
$this->x = $value;
524+
parent::$x::set($value);
522525
}
523526
}
524527
}

0 commit comments

Comments
 (0)