From 637715cad9d6b284176e89d591f28555f47c6862 Mon Sep 17 00:00:00 2001 From: Vincent Chareunphol Date: Tue, 3 Sep 2024 15:55:40 +0200 Subject: [PATCH] [PropertyAccess] Add an example for setter with a dynamic property --- components/property_access.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/property_access.rst b/components/property_access.rst index 78b125cd391..3056674ac4b 100644 --- a/components/property_access.rst +++ b/components/property_access.rst @@ -324,10 +324,12 @@ can use setters, the magic ``__set()`` method or properties to set values:: $propertyAccessor->setValue($person, 'firstName', 'Wouter'); $propertyAccessor->setValue($person, 'lastName', 'de Jong'); // setLastName is called $propertyAccessor->setValue($person, 'children', [new Person()]); // __set is called + $propertyAccessor->setValue($person, 'role', 'contributor'); // A new property 'role' is set dynamically var_dump($person->firstName); // 'Wouter' var_dump($person->getLastName()); // 'de Jong' var_dump($person->getChildren()); // [Person()]; + var_dump($person->role); // 'contributor'; You can also use ``__call()`` to set values but you need to enable the feature, see `Enable other Features`_::