1.2.17. Access Protected Structures¶
It is not allowed to access protected properties, methods or constants from outside the class or its relatives.
<?php
class foo {
protected $bar = 1;
}
$foo = new Foo();
$foo->bar = 2;
?>
See also Visibility. and Understanding The Concept Of Visibility In Object Oriented PHP.
1.2.17.2. Connex PHP features¶
1.2.17.2.1. Suggestions¶
Change ‘protected’ to ‘public’ to relax the constraint
Add a getter method to reach the target value
Remove the access to the protected value and find it another way
1.2.17.2.2. Specs¶
Short name |
Classes/AccessProtected |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |