I've been looking at my code for the forum I created and decided I wanted to reorganize all my includes and whatnot into a much simpler system. I started fiddling around with things and noticed this:
test();
function test()
{
echo 'The quick brown fox jumps over the lazy dog.';
}
This executes without issue as one would expect; even though the function was defined after it was used, there were no errors and the script behaved properly. Keeping on that same train of thought, I tried this:
echo TEST;
define('TEST', 'foobar');
And it produced a notice telling me the constant TEST was not defined. I find it interesting that in PHP you can use a function before its definition but not a constant. A quick peruse through the manual didn't mention why or anything related. I was under the impression the entire script is "compiled" or interpreted before executing, hence why something like a parse error can be detected if it's buried deep within a script.
Does anyone know why PHP behaves this way? I imagine there's a logical reason I guess I just don't know it. I'm using PHP 5.4.5 by the way.