@@ -51,8 +51,8 @@ method. This is done using the index notation that is used in PHP::
51
51
'first_name' => 'Wouter',
52
52
);
53
53
54
- echo $accessor->getValue($person, '[first_name]'); // 'Wouter'
55
- echo $accessor->getValue($person, '[age]'); // null
54
+ dump( $accessor->getValue($person, '[first_name]') ); // 'Wouter'
55
+ dump( $accessor->getValue($person, '[age]') ); // null
56
56
57
57
As you can see, the method will return ``null `` if the index does not exists.
58
58
@@ -68,8 +68,8 @@ You can also use multi dimensional arrays::
68
68
)
69
69
);
70
70
71
- echo $accessor->getValue($persons, '[0][first_name]'); // 'Wouter'
72
- echo $accessor->getValue($persons, '[1][first_name]'); // 'Ryan'
71
+ dump( $accessor->getValue($persons, '[0][first_name]') ); // 'Wouter'
72
+ dump( $accessor->getValue($persons, '[1][first_name]') ); // 'Ryan'
73
73
74
74
Reading from Objects
75
75
--------------------
@@ -86,13 +86,13 @@ To read from properties, use the "dot" notation::
86
86
$person = new Person();
87
87
$person->firstName = 'Wouter';
88
88
89
- echo $accessor->getValue($person, 'firstName'); // 'Wouter'
89
+ dump( $accessor->getValue($person, 'firstName') ); // 'Wouter'
90
90
91
91
$child = new Person();
92
92
$child->firstName = 'Bar';
93
93
$person->children = array($child);
94
94
95
- echo $accessor->getValue($person, 'children[0].firstName'); // 'Bar'
95
+ dump( $accessor->getValue($person, 'children[0].firstName') ); // 'Bar'
96
96
97
97
.. caution ::
98
98
@@ -122,7 +122,7 @@ property name (``first_name`` becomes ``FirstName``) and prefixes it with
122
122
123
123
$person = new Person();
124
124
125
- echo $accessor->getValue($person, 'first_name'); // 'Wouter'
125
+ dump( $accessor->getValue($person, 'first_name') ); // 'Wouter'
126
126
127
127
Using Hassers/Issers
128
128
~~~~~~~~~~~~~~~~~~~~
@@ -151,10 +151,10 @@ getters, this means that you can do something like this::
151
151
$person = new Person();
152
152
153
153
if ($accessor->getValue($person, 'author')) {
154
- echo 'He is an author';
154
+ dump( 'He is an author') ;
155
155
}
156
156
if ($accessor->getValue($person, 'children')) {
157
- echo 'He has children';
157
+ dump( 'He has children') ;
158
158
}
159
159
160
160
This will produce: ``He is an author ``
@@ -179,7 +179,7 @@ The ``getValue`` method can also use the magic ``__get`` method::
179
179
180
180
$person = new Person();
181
181
182
- echo $accessor->getValue($person, 'Wouter'); // array(...)
182
+ dump( $accessor->getValue($person, 'Wouter') ); // array(...)
183
183
184
184
Magic ``__call() `` Method
185
185
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -215,7 +215,7 @@ enable this feature by using :class:`Symfony\\Component\\PropertyAccess\\Propert
215
215
->enableMagicCall()
216
216
->getPropertyAccessor();
217
217
218
- echo $accessor->getValue($person, 'wouter'); // array(...)
218
+ dump( $accessor->getValue($person, 'wouter') ); // array(...)
219
219
220
220
.. versionadded :: 2.3
221
221
The use of magic ``__call() `` method was introduced in Symfony 2.3.
@@ -239,9 +239,9 @@ method::
239
239
240
240
$accessor->setValue($person, '[first_name]', 'Wouter');
241
241
242
- echo $accessor->getValue($person, '[first_name]'); // 'Wouter'
242
+ dump( $accessor->getValue($person, '[first_name]') ); // 'Wouter'
243
243
// or
244
- // echo $person['first_name']; // 'Wouter'
244
+ // dump( $person['first_name']) ; // 'Wouter'
245
245
246
246
Writing to Objects
247
247
------------------
@@ -275,9 +275,9 @@ can use setters, the magic ``__set`` method or properties to set values::
275
275
$accessor->setValue($person, 'lastName', 'de Jong');
276
276
$accessor->setValue($person, 'children', array(new Person()));
277
277
278
- echo $person->firstName; // 'Wouter'
279
- echo $person->getLastName(); // 'de Jong'
280
- echo $person->children; // array(Person());
278
+ dump( $person->firstName) ; // 'Wouter'
279
+ dump( $person->getLastName() ); // 'de Jong'
280
+ dump( $person->children) ; // array(Person());
281
281
282
282
You can also use ``__call `` to set values but you need to enable the feature,
283
283
see `Enable other Features `_.
@@ -313,7 +313,7 @@ see `Enable other Features`_.
313
313
314
314
$accessor->setValue($person, 'wouter', array(...));
315
315
316
- echo $person->getWouter(); // array(...)
316
+ dump( $person->getWouter() ); // array(...)
317
317
318
318
Mixing Objects and Arrays
319
319
-------------------------
@@ -345,7 +345,7 @@ You can also mix objects and arrays::
345
345
$accessor->setValue($person, 'children[0].firstName', 'Wouter');
346
346
// equal to $person->getChildren()[0]->firstName = 'Wouter'
347
347
348
- echo 'Hello '.$accessor->getValue($person, 'children[0].firstName'); // 'Wouter'
348
+ dump( 'Hello '.$accessor->getValue($person, 'children[0].firstName') ); // 'Wouter'
349
349
// equal to $person->getChildren()[0]->firstName
350
350
351
351
Enable other Features
0 commit comments