Skip to content

Improved the explanation of naming in PHP and Twig #10425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions contributing/code/standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@ Structure
Naming Conventions
~~~~~~~~~~~~~~~~~~

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

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

* Use namespaces for all classes;
* Use namespaces for all PHP classes and `UpperCamelCase`_ for their names (e.g.
``ConsoleLogger``);

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

* Suffix exceptions with ``Exception``;

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

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