From 0ab59ab28f95ba55457cc457cc4227d894cb735d Mon Sep 17 00:00:00 2001 From: Iulian Popa Date: Sun, 2 Apr 2017 17:00:06 +0300 Subject: [PATCH 1/5] Fix writing to objects example --- components/property_access.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/property_access.rst b/components/property_access.rst index bfe739e3e30..68291b929e7 100644 --- a/components/property_access.rst +++ b/components/property_access.rst @@ -245,9 +245,9 @@ can use setters, the magic ``__set()`` method or properties to set values:: { public $firstName; private $lastName; - private $children = array(); + public $children = array(); - public function setLastName($name) + public function getLastName() { $this->lastName = $name; } From 3c95b96ebd3729bcab3e4164ed3114b9f8164345 Mon Sep 17 00:00:00 2001 From: Iulian Popa Date: Sun, 2 Apr 2017 17:08:12 +0300 Subject: [PATCH 2/5] Delete extra parenthesis from decorator example --- service_container/service_decoration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service_container/service_decoration.rst b/service_container/service_decoration.rst index 1bd86f9e681..b090a311244 100644 --- a/service_container/service_decoration.rst +++ b/service_container/service_decoration.rst @@ -232,6 +232,6 @@ order by configuring the priority of decoration, this can be any integer number The generated code will be the following:: - $this->services['foo'] = new Baz(new Bar(new Foo()))); + $this->services['foo'] = new Baz(new Bar(new Foo())); .. _decorator pattern: https://en.wikipedia.org/wiki/Decorator_pattern From 4266a867460a48b148c6137d9aa2a4286b35de66 Mon Sep 17 00:00:00 2001 From: Iulian Popa Date: Thu, 4 May 2017 11:17:04 +0300 Subject: [PATCH 3/5] Update getLastName method --- components/property_access.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/property_access.rst b/components/property_access.rst index 68291b929e7..0d617b6f99c 100644 --- a/components/property_access.rst +++ b/components/property_access.rst @@ -249,7 +249,7 @@ can use setters, the magic ``__set()`` method or properties to set values:: public function getLastName() { - $this->lastName = $name; + return $this->lastName; } public function __set($property, $value) From 5219674ed53a50e10964d4ea0358881efc18f7a6 Mon Sep 17 00:00:00 2001 From: Iulian Popa Date: Fri, 5 May 2017 10:18:58 +0300 Subject: [PATCH 4/5] Fix the example of modifying object --- components/property_access.rst | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/components/property_access.rst b/components/property_access.rst index 0d617b6f99c..1bf2caacbaa 100644 --- a/components/property_access.rst +++ b/components/property_access.rst @@ -245,11 +245,11 @@ can use setters, the magic ``__set()`` method or properties to set values:: { public $firstName; private $lastName; - public $children = array(); + private $children = array(); - public function getLastName() + public function setLastName($name) { - return $this->lastName; + $this->lastName = $name; } public function __set($property, $value) @@ -257,18 +257,24 @@ can use setters, the magic ``__set()`` method or properties to set values:: $this->$property = $value; } - // ... + public function getLastName() { + return $this->lastName; + } + + public function getChildren() { + return $this->children; + } } $person = new Person(); $accessor->setValue($person, 'firstName', 'Wouter'); - $accessor->setValue($person, 'lastName', 'de Jong'); - $accessor->setValue($person, 'children', array(new Person())); + $accessor->setValue($person, 'lastName', 'de Jong'); // setLastName is called + $accessor->setValue($person, 'children', array(new Person())); // __set is called var_dump($person->firstName); // 'Wouter' var_dump($person->getLastName()); // 'de Jong' - var_dump($person->children); // array(Person()); + var_dump($person->getChildren()); // array(Person()); You can also use ``__call()`` to set values but you need to enable the feature, see `Enable other Features`_. From 2a617134e76f00e658a86522a338f5659c0dd1af Mon Sep 17 00:00:00 2001 From: Iulian Popa Date: Fri, 5 May 2017 11:23:21 +0300 Subject: [PATCH 5/5] Fix codestyle --- components/property_access.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/property_access.rst b/components/property_access.rst index 1bf2caacbaa..dde7230660a 100644 --- a/components/property_access.rst +++ b/components/property_access.rst @@ -252,18 +252,20 @@ can use setters, the magic ``__set()`` method or properties to set values:: $this->lastName = $name; } - public function __set($property, $value) + public function getLastName() { - $this->$property = $value; - } - - public function getLastName() { return $this->lastName; } - public function getChildren() { + public function getChildren() + { return $this->children; } + + public function __set($property, $value) + { + $this->$property = $value; + } } $person = new Person();