Suppose we have following function in PHP:
public function testSomething()
{
$name = perform_sql_query("SELECT name FROM table WHERE id = $entity_id;");
assert($name == "some_name");
}
Query is syntactically correct, but since $entity_id is undefined - query will always search for 'id = 0', which is semantically incorrect.
I would like such functions to fail automatically, when they try to use undefined variable. Is there such mechanism in PHP? Or maybe there is some tool, that can be used to analyze PHP source code to find such cases?
UPDATE Those undefined variables can occur anywhere in project, so correct decision will be to check function arguments in every function.
UPDATE2 Setting error handler helped. Now anytime uninitialized variable is used - exception is thrown.