Warn against writing to undeclared properties
Summary: I make this error quite often: I forget to declare a property I am writing to or I make a typo in it. PHP implicitly creates a public property which I don't like. I would much rather see a linter warning me against this than this runtime check but writing it is very difficult: - We need to explore all parents of the class we are checking. - It is even possible that children will declare that property but it's OK to treat this as error anyway. - We can extend also builtin or external classes. - It's somewhat doable for `$this` but even more complex for any `$obj` because we don't know the class of it. This should catch significant part of these errors and I'm fine with that. I don't plan escalating to exception because this error is not fatal and should not stop the application from working. Test Plan: Loaded homepage, checked log. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3601
This commit is contained in:
@@ -61,4 +61,9 @@ abstract class AphrontController {
|
||||
return $this->currentApplication;
|
||||
}
|
||||
|
||||
public function __set($name, $value) {
|
||||
phlog('Wrote to undeclared property '.get_class($this).'::$'.$name.'.');
|
||||
$this->$name = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user