Suppose we have the following function in PHP:
public function testSomething()
{
$name = perform_sql_query("SELECT name FROM table WHERE id = $entity_id;");
assert($name == "some_name");
}
The request is syntactically correct, but since $ entity_id is undefined, the request will always look for "id = 0", which is semantically incorrect.
I would like these functions to be executed automatically when they tried to use the undefined variable. Is there such a mechanism in PHP? Or maybe there is some tool that can be used to analyze the PHP source code to find such cases?
UPDATE These undefined variables can occur anywhere in the project, so checking the function arguments in each function is the right solution.
UPDATE2 Help Setup Assistant. Now at any time an uninitialized variable is used - an exception is thrown.
source
share