I just spent 3 hours wondering why I couldn’t start a session, then realised that I used:
session_start;
when I should have used:
session_start();
I received no error messages at all!
Perhaps then, I thought, it’s a lazy way to differentiate functions from variables – but then remembered that it can’t be as variables require a $
Can anyone tell me why parentheses are required then, and also why no error is given when they aren’t used?
I get the notice (Having set error_reporting to
E_ALL):A function always needs the parentheses as else (as you can see) you can’t tell the difference between a function and a constant. As code should be written so it can be understood by the human reading it, not allowing the reader to see if it is a constant or function call makes it that bit harder to read and debug.
I assume it is a notice rather than an error error due to backwards compatibility in that some older code tends to access arrays using unquoted strings which PHP would treat as quoted strings if there wasn’t a constant with that name.