You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Property hooks are called whenever a property is accessed (except from within the hook itself of course), which means that the custom get/set methods this library allows would conflict when a custom method is defined for a property that also has a hook defined.
145
+
To prevent double method calls, the internal methods `hasSetHook()` and `hasGetHook()` have been introduced, and are called whenever the magic get/set methods are called: when both, a custom method and a property hook exist, only the property hook will be called.
146
+
<br/>Public properties will never call the magic get/set, however, their hooks *will* be called. (un)serializing a `SettingsContainerInterface` instance will bypass magic get/set and existing property hooks, while JSON de/encode as will call magic get/set or existing hooks explicitly via the `toArray()` and `fromIterable()` methods.
147
+
148
+
```php
149
+
class PropertyHooksContainer extends SettingsContainerAbstract{
150
+
151
+
protected string $someValue{
152
+
set => doStuff($value);
153
+
}
154
+
155
+
// this method will be ignored in magic calls as a "set" hook on the property exists
156
+
protected function set_someValue(string $value):void{
157
+
$this->someValue = doOtherStuff($value);
158
+
}
159
+
160
+
// this custom method will be called as the property has no "get" hook
161
+
protected function get_someValue():string{
162
+
return doWhatever($this->someValue);
163
+
}
164
+
165
+
// this property will never trigger the magic get/set and associated methods
|`construct()`| void | calls a method with trait name as replacement constructor for each used trait |
203
+
|`isPrivate(string $property)`| bool | private properties are excluded from magic calls |
204
+
|`hasSetHook(string $property)`| bool ||
205
+
|`hasGetHook(string $property)`| bool ||
206
+
207
+
165
208
## Disclaimer
166
209
This might be either an absolutely brilliant or completely stupid idea - you decide. (in hindsight it was a great idea I guess - property hooks made their way into PHP 8.4)
167
210
Also, this is not a dependency injection container. Stop using DI containers FFS.
0 commit comments