PropertyDeclaration
Verifies that properties are declared correctly.
Scope
PSR2.Classes.PropertyDeclaration
Description
Property names should not be prefixed with an underscore to indicate visibility. Visibility should be used to declare properties rather than the var keyword. Only one property should be declared within a statement. The static declaration must come after the visibility declaration.
Usage
<rule ref="PSR2.Classes.PropertyDeclaration"></rule>
Examples
Example 1
Valid: Correct property naming.
class Foo
{
private $bar;
}
Invalid: An underscore prefix used to indicate visibility.
class Foo
{
private $_bar;
}
Example 2
Valid: Visibility of property declared.
class Foo
{
private $bar;
}
Invalid: Var keyword used to declare property.
class Foo
{
var $bar;
}
Example 3
Valid: One property declared per statement.
class Foo
{
private $bar;
private $baz;
}
Invalid: Multiple properties declared in one statement.
class Foo
{
private $bar, $baz;
}
Example 4
Valid: If declared as static, the static declaration must come after the visibility declaration.
class Foo
{
public static $bar;
private $baz;
}
Invalid: Static declaration before the visibility declaration.
class Foo
{
<em>static<em> protected $bar;
}