Rule Definition
In PHP source code if there is a write action to a property that does not exist and there is no '__set'-method, the property will be created. The '__get' method will only be called if there is no property with the given name. So having properties without a __set method could produce unexpected values for the __get method of the same property.
Remediation
Modify the source code and add the '__set' method with an appropriate default. Also consider throwing an Exception that returns false.
Violation Code Sample
<?php
$rec = new Rectangle(5, 5);
echo $rec->area; //outputs 25
?>
Fixed Code Sample
<?php
$rec->area = 10;
echo $rec->area; //outputs 10
?>
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.