mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
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:
parent
7c39c4ca7d
commit
4682e0c104
3 changed files with 22 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1796,4 +1796,15 @@ abstract class LiskDAO {
|
|||
|
||||
throw new Exception("Unable to resolve method '{$method}'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Warns against writing to undeclared property.
|
||||
*
|
||||
* @task util
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
phlog('Wrote to undeclared property '.get_class($this).'::$'.$name.'.');
|
||||
$this->$name = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -49,4 +49,9 @@ abstract class AphrontView {
|
|||
|
||||
abstract public function render();
|
||||
|
||||
public function __set($name, $value) {
|
||||
phlog('Wrote to undeclared property '.get_class($this).'::$'.$name.'.');
|
||||
$this->$name = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue