0

what is the difference of declaring a property in a class (in PHP) as :

$_city;

or

$city;

is there a difference in variable scope when start naming by underscore?

thanks,

zahra_oveyedzade
  • 988
  • 10
  • 17
  • No. Having underscore in front of a variable name is just a *naming convention* which some people prefer to use for Private variables. But unless you explicitly specify `private` keyword in front of variable declaration, it would not make them private by themselves – Madhur Bhaiya Oct 06 '19 at 07:41
  • There is no difference, just naming convention. According to PSR-2 standard it shouldn't be done anymore: "Property names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility." – equi Oct 06 '19 at 07:44

0 Answers0