Skip to content

Commit 5edc033

Browse files
committed
minor #10425 Improved the explanation of naming in PHP and Twig (javiereguiluz)
This PR was merged into the 2.8 branch. Discussion ---------- Improved the explanation of naming in PHP and Twig A user asked about this on Slack and I don't think the current doc is clear enough. Commits ------- 4eda37d Improved the explanation of naming in PHP and Twig
2 parents 64c7714 + 4eda37d commit 5edc033

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

contributing/code/standards.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,14 @@ Structure
199199
Naming Conventions
200200
~~~~~~~~~~~~~~~~~~
201201

202-
* Use camelCase, not underscores, for variable, function and method
203-
names, arguments;
202+
* Use `camelCase`_ for PHP variables, function and method names, arguments
203+
(e.g. ``$acceptableContentTypes``, ``hasSession()``);
204204

205-
* Use underscores for configuration options and parameters;
205+
* Use `snake_case`_ for configuration parameters and Twig template variables
206+
(e.g. ``framework.csrf_protection``, ``http_status_code``);
206207

207-
* Use namespaces for all classes;
208+
* Use namespaces for all PHP classes and `UpperCamelCase`_ for their names (e.g.
209+
``ConsoleLogger``);
208210

209211
* Prefix all abstract classes with ``Abstract`` except PHPUnit ``*TestCase``.
210212
Please note some early Symfony classes do not follow this convention and
@@ -217,7 +219,9 @@ Naming Conventions
217219

218220
* Suffix exceptions with ``Exception``;
219221

220-
* Use alphanumeric characters and underscores for file names;
222+
* Use UpperCamelCase for naming PHP files (e.g. ``EnvVarProcessor.php``) and
223+
snake case for naming Twig templates and web assets (``section_layout.html.twig``,
224+
``index.scss``);
221225

222226
* For type-hinting in PHPDocs and casting, use ``bool`` (instead of ``boolean``
223227
or ``Boolean``), ``int`` (instead of ``integer``), ``float`` (instead of
@@ -274,3 +278,6 @@ License
274278
.. _`PSR-4`: https://www.php-fig.org/psr/psr-4/
275279
.. _`identical comparison`: https://php.net/manual/en/language.operators.comparison.php
276280
.. _`Yoda conditions`: https://en.wikipedia.org/wiki/Yoda_conditions
281+
.. _`camelCase`: https://en.wikipedia.org/wiki/Camel_case
282+
.. _`UpperCamelCase`: https://en.wikipedia.org/wiki/Camel_case
283+
.. _`snake_case`: https://en.wikipedia.org/wiki/Snake_case

0 commit comments

Comments
 (0)