[wp-trac] [WordPress Trac] #22234: Use access modifiers in classes, not the var keyword
WordPress Trac
noreply at wordpress.org
Sat Oct 20 21:23:39 UTC 2012
#22234: Use access modifiers in classes, not the var keyword
----------------------------+-------------------------
Reporter: wonderboymusic | Type: enhancement
Status: new | Priority: normal
Milestone: Future Release | Component: General
Version: 1.5 | Severity: normal
Keywords: has-patch |
----------------------------+-------------------------
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
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22234>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list