Allow underscores in PHP variable names (ref. php:S117)

I noticed that the php:S117 rule defines a regex expression that is a subset of what is considered a standard PHP naming convention, by excluding the underscore sign (“_”) from it.

Instead of the current:


it should be


unless there’s a reason I’m not aware of.

Thank you!

Hello @Sergio_Carabetta and welcome to community!

Thanks for raising awareness on this topic.
Indeed I couldn’t find any claim or strong reference about excluding the usage of the underscore sign.

From my understanding, there is no standard among the community. Some frameworks such as Symfony/Zend tend to use/encourage the use of camelCase, while some others such as WordPress/CodeIgniter tend to prefer snake_case.

Also the PHP-FIG through their PSR does not provide direction about this, it is even mentioning in its PSR-1: Basic Coding Standard this:

This guide intentionally avoids any recommendation regarding the use of $StudlyCaps, $camelCase, or $under_score property names.
Whatever naming convention is used SHOULD be applied consistently within a reasonable scope. That scope may be vendor-level, package-level, class-level, or method-level.

As per this, I have created a ticket to initiate the change you suggested.

Please also note that this rule is configurable and you can modify the regex on your SonarQube instance, in case you want to enforce a specific format.


Thank you, Rudy! Glad to contribute!