Use access modifiers in classes, not the var keyword
|Reported by:||wonderboymusic||Owned by:|
The minimum required PHP version is 5.2.4. The var keyword is a relic of PHP 4. Let us open our hymnals to php.net:
Note: The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning.
PHP 5 has much better support for OO features like access modifiers in classes. WP also has a history of including PHPDoc blocks with code and using the @access tag. However, the tag is meaningless if it doesn't match the supplied access modifier.
PHPDoc blocks are present 1) for inline documentation, sure but mainly 2) to allow automatic generation of documentation when used with a command-line tool like phpDocumentor or (IMO, the far superior) ApiGen.
If I specify the following:
/** * @access private */ var $prop;
$prop will appear in the documentation as public because var means public.
I have modified class properties throughout the codebase to use access modifiers instead of var.
- If no PHPDoc was present, I made the property public, which it already was.
- If the @access tag was present, I used its value for the property.
- I then ran Unit Tests which produced some immediate fatal errors do to existing core code that was trying to access properties in a public way that had @access set to private.
- I altered those properties to indeed be public and updated the PHPDoc
Change History (82)
comment:12 @nacin — 2 years ago
- Component changed from General to Inline Docs
- Milestone changed from 3.7 to Future Release
- Resolution set to fixed
- Status changed from new to closed