Skip to content

Commit

Permalink
Fix hooks example (#4392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell authored Jan 27, 2025
1 parent c39225b commit 8c80c20
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions language/oop5/property-hooks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,10 @@ class PositivePoint extends Point
Hooks may not access any other hook except their own parent on their own property.
</simpara>
<simpara>
The example above could be rewritten more efficiently as follows.
The example above could be rewritten as follows, which would allow for the
<literal>Point</literal> class to add its own <literal>set</literal> hook
in the future without issue. (In the previous example, a hook added to
the parent class would be ignored in the child.)
</simpara>
<example>
<title>Parent hook access (set)</title>
Expand All @@ -518,7 +521,7 @@ class PositivePoint extends Point
if ($value < 0) {
throw new \InvalidArgumentException('Too small');
}
$this->x = $value;
parent::$x::set($value);
}
}
}
Expand Down

0 comments on commit 8c80c20

Please sign in to comment.