8000 minor #5451 [#5388] change echo and print in examples (snoek09) · symfony/symfony-docs@4f3ce84 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f3ce84

Browse files
committed
minor #5451 [#5388] change echo and print in examples (snoek09)
This PR was merged into the 2.3 branch. Discussion ---------- [#5388] change echo and print in examples This is a split of #5388 for the 2.3 branch. Original description: > | Q | A > | ------------- | --- > | Doc fix? | yes > | New docs? | no > | Applies to | all > | Fixed tickets | #5177 > > Original PR and discussion in #5285 > > Change echo/print in examples to use: > > - `var_dump()` in components docs > - `dump()` in framework docs Commits ------- 37db975 5177 use var_dump() in components 9fa1c11 5177 use var_dump() in components c2acbee 5177 add die() after dump() 78c9b7c 5177 use dump() instead of print in examples 10898c9 5177 use dump() instead of echo in examples
2 parents 78054b2 + 37db975 commit 4f3ce84

File tree

16 files changed

+58
-53
lines changed

16 files changed

+58
-53
lines changed

book/doctrine.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,8 @@ to the given ``Category`` object via their ``category_id`` value.
12041204
$category = $product->getCategory();
12051205

12061206
// prints "Proxies\AppBundleEntityCategoryProxy"
1207-
echo get_class($category);
1207+
dump(get_class($category));
1208+
die();
12081209

12091210
This proxy object extends the true ``Category`` object, and looks and
12101211
acts exactly like it. The difference is that, by using a proxy object,

book/translation.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ wrapping each with a function capable of translating the text (or "message")
1212
into the language of the user::
1313

1414
// text will *always* print out in English
15-
echo 'Hello World';
15+
dump('Hello World');
16+
die();
1617

1718
// text can be translated into the end-user's language or
1819
// default to English
19-
echo $translator->trans('Hello World');
20+
dump($translator->trans('Hello World'));
21+
die();
2022

2123
.. note::
2224

components/class_loader/class_map_generator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ method::
5050

5151
use Symfony\Component\ClassLoader\ClassMapGenerator;
5252

53-
print_r(ClassMapGenerator::createMap(__DIR__.'/library'));
53+
var_dump(ClassMapGenerator::createMap(__DIR__.'/library'));
5454

5555
Given the files and class from the table above, you should see an output like
5656
this:

components/css_selector.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ equivalents::
5151

5252
use Symfony\Component\CssSelector\CssSelector;
5353

54-
print CssSelector::toXPath('div.item > h4 > a');
54+
var_dump(CssSelector::toXPath('div.item > h4 > a'));
5555

5656
This gives the following output:
5757

components/dom_crawler.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ traverse easily::
4747
$crawler = new Crawler($html);
4848

4949
foreach ($crawler as $domElement) {
50-
print $domElement->nodeName;
50+
var_dump($domElement->nodeName);
5151
}
5252

5353
Specialized :class:`Symfony\\Component\\DomCrawler\\Link` and

components/event_dispatcher/generic_event.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ the event arguments::
7575
);
7676
$dispatcher->dispatch('foo', $event);
7777

78-
echo $event['counter'];
78+
var_dump($event['counter']);
7979

8080
class FooListener
8181
{
@@ -96,7 +96,7 @@ Filtering data::
9696
$event = new GenericEvent($subject, array('data' => 'Foo'));
9797
$dispatcher->dispatch('foo', $event);
9898

99-
echo $event['data'];
99+
var_dump($event['data']);
100100

101101
class FooListener
102102
{
@@ -105,3 +105,4 @@ Filtering data::
105105
$event['data'] = strtolower($event['data']);
106106
}
107107
}
108+

components/event_dispatcher/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ part of the listener's processing logic::
635635
{
636636
public function myEventListener(Event $event)
637637
{
638-
echo $event->getName();
638+
// ... do something with the event name
639639
}
640640
}
641641

components/finder.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ directories::
3030
$finder->files()->in(__DIR__);
3131

3232
foreach ($finder as $file) {
33-
// Print the absolute path
34-
print $file->getRealpath()."\n";
33+
// Dump the absolute path
34+
var_dump($file->getRealpath());
3535

36-
// Print the relative path to the file, omitting the filename
37-
print $file->getRelativePath()."\n";
36+
// Dump the relative path to the file, omitting the filename
37+
var_dump($file->getRelativePath());
3838

39-
// Print the relative path to the file
40-
print $file->getRelativePathname()."\n";
39+
// Dump the relative path to the file
40+
var_dump($file->getRelativePathname());
4141
}
4242

4343
The ``$file`` is an instance of :class:`Symfony\\Component\\Finder\\SplFileInfo`
@@ -121,9 +121,7 @@ And it also works with user-defined streams::
121121
$finder = new Finder();
122122
$finder->name('photos*')->size('< 100K')->date('since 1 hour ago');
123123
foreach ($finder->in('s3://bucket-name') as $file) {
124-
// ... do something
125-
126-
print $file->getFilename()."\n";
124+
// ... do something with the file
127125
}
128126

129127
.. note::

components/form/introduction.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ is created from the form factory.
396396
->add('dueDate', 'date')
397397
->getForm();
398398
399-
echo $twig->render('new.html.twig', array(
399+
var_dump($twig->render('new.html.twig', array(
400400
'form' => $form->createView(),
401-
));
401+
)));
402402
403403
.. code-block:: php-symfony
404404

components/http_foundation/introduction.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ represented by a PHP callable instead of a string::
415415

416416
$response = new StreamedResponse();
417417
$response->setCallback(function () {
418-
echo 'Hello World';
418+
var_dump('Hello World');
419419
flush();
420420
sleep(2);
421-
echo 'Hello World';
421+
var_dump('Hello World');
422422
flush();
423423
});
424424
$response->send();

components/intl.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ This class currently only works with the `intl extension`_ installed::
217217
$reader = new BinaryBundleReader();
218218
$data = $reader->read('/path/to/bundle', 'en');
219219

220-
echo $data['Data']['entry1'];
220+
var_dump($data['Data']['entry1']);
221221

222222
PhpBundleReader
223223
~~~~~~~~~~~~~~~
@@ -231,7 +231,7 @@ object::
231231
$reader = new PhpBundleReader();
232232
$data = $reader->read('/path/to/bundle', 'en');
233233

234-
echo $data['Data']['entry1'];
234+
var_dump($data['Data']['entry1']);
235235

236236
BufferedBundleReader
237237
~~~~~~~~~~~~~~~~~~~~
@@ -272,10 +272,10 @@ returned::
272272
$data = $reader->read('/path/to/bundle', 'en');
273273

274274
// Produces an error if the key "Data" does not exist
275-
echo $data['Data']['entry1'];
275+
var_dump($data['Data']['entry1']);
276276

277277
// Returns null if the key "Data" does not exist
278-
echo $reader->readEntry('/path/to/bundle', 'en', array('Data', 'entry1'));
278+
var_dump($reader->readEntry('/path/to/bundle', 'en', array('Data', 'entry1')));
279279

280280
Additionally, the
281281
:method:`Symfony\\Component\\Intl\\ResourceBundle\\Reader\\StructuredBundleReaderInterface::readEntry`
@@ -286,12 +286,12 @@ multi-valued entries (arrays), the values of the more specific and the fallback
286286
locale will be merged. In order to suppress this behavior, the last parameter
287287
``$fallback`` can be set to ``false``::
288288

289-
echo $reader->readEntry(
289+
var_dump($reader->readEntry(
290290
'/path/to/bundle',
291291
'en',
292292
array('Data', 'entry1'),
293293
false
294-
);
294+
));
295295

296296
Accessing ICU Data
297297
------------------

components/property_access/introduction.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ method. This is done using the index notation that is used in PHP::
5151
'first_name' => 'Wouter',
5252
);
5353

54-
echo $accessor->getValue($person, '[first_name]'); // 'Wouter'
55-
echo $accessor->getValue($person, '[age]'); // null
54+
var_dump($accessor->getValue($person, '[first_name]')); // 'Wouter'
55+
var_dump($accessor->getValue($person, '[age]')); // null
5656

5757
As you can see, the method will return ``null`` if the index does not exists.
5858

@@ -68,8 +68,8 @@ You can also use multi dimensional arrays::
6868
)
6969
);
7070

71-
echo $accessor->getValue($persons, '[0][first_name]'); // 'Wouter'
72-
echo $accessor->getValue($persons, '[1][first_name]'); // 'Ryan'
71+
var_dump($accessor->getValue($persons, '[0][first_name]')); // 'Wouter'
72+
var_dump($accessor->getValue($persons, '[1][first_name]')); // 'Ryan'
7373

7474
Reading from Objects
7575
--------------------
@@ -86,13 +86,13 @@ To read from properties, use the "dot" notation::
8686
$person = new Person();
8787
$person->firstName = 'Wouter';
8888

89-
echo $accessor->getValue($person, 'firstName'); // 'Wouter'
89+
var_dump($accessor->getValue($person, 'firstName')); // 'Wouter'
9090

9191
$child = new Person();
9292
$child->firstName = 'Bar';
9393
$person->children = array($child);
9494

95-
echo $accessor->getValue($person, 'children[0].firstName'); // 'Bar'
95+
var_dump($accessor->getValue($person, 'children[0].firstName')); // 'Bar'
9696

9797
.. caution::
9898

@@ -122,7 +122,7 @@ property name (``first_name`` becomes ``FirstName``) and prefixes it with
122122

123123
$person = new Person();
124124

125-
echo $accessor->getValue($person, 'first_name'); // 'Wouter'
125+
var_dump($accessor->getValue($person, 'first_name')); // 'Wouter'
126126

127127
Using Hassers/Issers
128128
~~~~~~~~~~~~~~~~~~~~
@@ -151,10 +151,10 @@ getters, this means that you can do something like this::
151151
$person = new Person();
152152

153153
if ($accessor->getValue($person, 'author')) {
154-
echo 'He is an author';
154+
var_dump('He is an author');
155155
}
156156
if ($accessor->getValue($person, 'children')) {
157-
echo 'He has children';
157+
var_dump('He has children');
158158
}
159159

160160
This will produce: ``He is an author``
@@ -179,7 +179,7 @@ The ``getValue`` method can also use the magic ``__get`` method::
179179

180180
$person = new Person();
181181

182-
echo $accessor->getValue($person, 'Wouter'); // array(...)
182+
var_dump($accessor->getValue($person, 'Wouter')); // array(...)
183183

184184
Magic ``__call()`` Method
185185
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -215,7 +215,7 @@ enable this feature by using :class:`Symfony\\Component\\PropertyAccess\\Propert
215215
->enableMagicCall()
216216
->getPropertyAccessor();
217217

218-
echo $accessor->getValue($person, 'wouter'); // array(...)
218+
var_dump($accessor->getValue($person, 'wouter')); // array(...)
219219

220220
.. versionadded:: 2.3
221221
The use of magic ``__call()`` method was introduced in Symfony 2.3.
@@ -239,9 +239,9 @@ method::
239239

240240
$accessor->setValue($person, '[first_name]', 'Wouter');
241241

242-
echo $accessor->getValue($person, '[first_name]'); // 'Wouter'
242+
var_dump($accessor->getValue($person, '[first_name]')); // 'Wouter'
243243
// or
244-
// echo $person['first_name']; // 'Wouter'
244+
// var_dump($person['first_name']); // 'Wouter'
245245

246246
Writing to Objects
247247
------------------
@@ -275,9 +275,9 @@ can use setters, the magic ``__set`` method or properties to set values::
275275
$accessor->setValue($person, 'lastName', 'de Jong');
276276
$accessor->setValue($person, 'children', array(new Person()));
277277

278-
echo $person->firstName; // 'Wouter'
279-
echo $person->getLastName(); // 'de Jong'
280-
echo $person->children; // array(Person());
278+
var_dump($person->firstName); // 'Wouter'
279+
var_dump($person->getLastName()); // 'de Jong'
280+
var_dump($person->children); // array(Person());
281281

282282
You can also use ``__call`` to set values but you need to enable the feature,
283283
see `Enable other Features`_.
@@ -313,7 +313,7 @@ see `Enable other Features`_.
313313
314314
$accessor->setValue($person, 'wouter', array(...));
315315
316-
echo $person->getWouter(); // array(...)
316+
var_dump($person->getWouter()); // array(...)
317317
318318
Mixing Objects and Arrays
319319
-------------------------
@@ -345,7 +345,7 @@ You can also mix objects and arrays::
345345
$accessor->setValue($person, 'children[0].firstName', 'Wouter');
346346
// equal to $person->getChildren()[0]->firstName = 'Wouter'
347347

348-
echo 'Hello '.$accessor->getValue($person, 'children[0].firstName'); // 'Wouter'
348+
var_dump('Hello '.$accessor->getValue($person, 'children[0].firstName')); // 'Wouter'
349349
// equal to $person->getChildren()[0]->firstName
350350

351351
Enable other Features

components/security/authorization.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ first constructor argument::
186186

187187
$role = new Role('ROLE_ADMIN');
188188

189-
// will echo 'ROLE_ADMIN'
190-
echo $role->getRole();
189+
// will show 'ROLE_ADMIN'
190+
var_dump($role->getRole());
191191

192192
.. note::
193193

@@ -247,3 +247,4 @@ decision manager::
247247
if (!$securityContext->isGranted('ROLE_ADMIN')) {
248248
throw new AccessDeniedException();
249249
}
250+

components/translation/custom_formats.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Once created, it can be used as any other loader::
6363

6464
$translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'fr_FR');
6565

66-
echo $translator->trans('welcome');
66+
var_dump($translator->trans('welcome'));
6767

6868
It will print *"accueil"*.
6969

@@ -116,3 +116,4 @@ YAML file are dumped into a text file with the custom format::
116116

117117
$dumper = new MyFormatDumper();
118118
$dumper->dump($catalogue, array('path' => __DIR__.'/dumps'));
119+

components/translation/usage.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Imagine you want to translate the string *"Symfony is great"* into French::
1515
'Symfony is great!' => 'J\'aime Symfony!',
1616
), 'fr_FR');
1717

18-
echo $translator->trans('Symfony is great!');
18+
var_dump($translator->trans('Symfony is great!'));
1919

2020
In this example, the message *"Symfony is great!"* will be translated into
2121
the locale set in the constructor (``fr_FR``) if the message exists in one of
3131
// ...
3232
$translated = $translator->trans('Hello '.$name);
3333

34-
echo $translated;
34+
var_dump($translated);
3535

3636
However, creating a translation for this string is impossible since the translator
3737
will try to look up the exact message, including the variable portions
@@ -45,7 +45,7 @@ variable with a "placeholder"::
4545
array('%name%' => $name)
4646
);
4747

48-
echo $translated;
48+
var_dump($translated);
4949

5050
Symfony will now look for a translation of the raw message (``Hello %name%``)
5151
and *then* replace the placeholders with their values. Creating a translation

cookbook/bundles/remove.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ can remove the ``Acme`` directory as well.
7979
:method:`Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface::getPath` method
8080
to get the path of the bundle::
8181

82-
echo $this->container->get('kernel')->getBundle('AcmeDemoBundle')->getPath();
82+
dump($this->container->get('kernel')->getBundle('AcmeDemoBundle')->getPath());
83+
die();
8384

8485
3.1 Remove Bundle Assets
8586
~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)
0