Undefined Variable

../_images/undefined_variable.png

The variable is undefined, and yet this is reported on the actual line where the variable is defined!

In fact, the assignation to $x appears to be the definition of the variable, because we, as human, encounter it first while reading.

Upon close inspection, the variable is actually used in the call to the function foo: PHP evaluates the arguments before calling the function, and finally, make the assignation. So the $x, used as second parameter in the foo call, is actually the first usage of the variable $x. Hence, the error message.

See Also

PHP Error Messages

PHP Features