-
Notifications
You must be signed in to change notification settings - Fork 0
Description
| Sniff basics | - |
|---|---|
| Fixable for PHP: | 5.0+ |
| Sniff type: | Modernize |
| Fixer type: | Safe (review recommended) |
Short description of the sniff
Prior to PHP 5, the var keyword had to be used to declare class properties and all properties were public. As of PHP 5.0, there is a choice between declaring properties as public, protected or private.
Related PHPCompatibility sniff(s):
- N/A
PHP manual references:
-
In order to maintain backward compatibility with PHP 4, PHP 5 will still accept the use of the keyword var in property declarations instead of (or in addition to) public, protected, or private. However, var is no longer required. In versions of PHP from 5.0 to 5.1.3, the use of var was considered deprecated and would issue an E_STRICT warning, but since PHP 5.1.3 it is no longer deprecated and does not issue the warning.
If you declare a property using var instead of one of public, protected, or private, then PHP 5 will treat the property as if it had been declared as public.
Example code:
Detect the following code pattern(s):
class OldStyle {
var $myproperty = 'abc';
}And fix these to:
class OldStyle {
public $myproperty = 'abc';
}Notes for implementation of the sniff:
- Also see: https://wiki.php.net/rfc/var_deprecation (declined) and https://gist.github.com/colinodell/5fb5e5d474674f294a38