This will throw an error:
class foo
{
var $bar;
public function getBar()
{
return $this->Bar; // beware of capital 'B': "Fatal: unknown property".
}
}
But this won't:
class foo
{
var $bar;
public function setBar($val)
{
$this->Bar = $val; // beware of capital 'B': silently defines a new prop "Bar"
}
}
How can I force PHP to throw errors in BOTH cases? I consider the second case more critical than the first (as it took me 2 hours to search for a d....ned typo in a property).
Baris defined viaissetBarisn't defined in the class.phpcs) to enforce it. Also, erroneous variable names will give you a perfectly understandable error message, which you can use to quickly find out where the error occurred. Using the magic methods__getand__setmay solve the problem, but at what cost? It will slow down the code, and it may give rise to another set of problems.