Skip to content

Commit 76424ea

Browse files
committed
minor #7870 Property access (iulyanp)
This PR was squashed before being merged into the master branch (closes #7870). Discussion ---------- Property access Hello, I changed the visibility of the `$children` property and use the `getLastName` method in order for the example to work correctly. Commits ------- 4301f63 Property access
2 parents 5879757 + 4301f63 commit 76424ea

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

components/property_access.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,31 @@ can use setters, the magic ``__set()`` method or properties to set values::
252252
$this->lastName = $name;
253253
}
254254

255+
public function getLastName()
256+
{
257+
return $this->lastName;
258+
}
259+
260+
public function getChildren()
261+
{
262+
return $this->children;
263+
}
264+
255265
public function __set($property, $value)
256266
{
257267
$this->$property = $value;
258268
}
259-
260-
// ...
261269
}
262270

263271
$person = new Person();
264272

265273
$accessor->setValue($person, 'firstName', 'Wouter');
266-
$accessor->setValue($person, 'lastName', 'de Jong');
267-
$accessor->setValue($person, 'children', array(new Person()));
274+
$accessor->setValue($person, 'lastName', 'de Jong'); // setLastName is called
275+
$accessor->setValue($person, 'children', array(new Person())); // __set is called
268276

269277
var_dump($person->firstName); // 'Wouter'
270278
var_dump($person->getLastName()); // 'de Jong'
271-
var_dump($person->children); // array(Person());
279+
var_dump($person->getChildren()); // array(Person());
272280

273281
You can also use ``__call()`` to set values but you need to enable the feature,
274282
see `Enable other Features`_.

service_container/service_decoration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,6 @@ order by configuring the priority of decoration, this can be any integer number
232232
233233
The generated code will be the following::
234234

235-
$this->services['foo'] = new Baz(new Bar(new Foo())));
235+
$this->services['foo'] = new Baz(new Bar(new Foo()));
236236

237237
.. _decorator pattern: https://en.wikipedia.org/wiki/Decorator_pattern

0 commit comments

Comments
 (0)