My server provider recently and unexpectedly updated my configuration when updating cPanel and broke my website. I've temporarily worked around this by configuring parsing with php4, but would rather fix the problem and not the symptom.
In my code, I use several libraries and use and the following mechanic to keep an entire file from being included again in subsequent require calls:
(For reasons I don't quite remember, require_once was not working when the application was being developed.)
For some reason this is being ignored and the old "Cannot redeclare" error occurs for files that are only included once in php4. For testing, I used the function_exits call to conditionally include the first function and the next function will then cause the error (none are system function names or even remotely reserved). Adding this code to hundreds of functions isn't very smart either when the entire file should not be executed again.
What's changed in php5 that causes this defined/define mechanic to unexpectedly fail? What needs to be changed to fix this?
NOTE: I was able to reproduce this error by requiring FileB and FileC in FileA, when FileC also requires FileB. I used the define/defined mechanic in all files with the appropriate values. I confirmed, with get_defined_constants, that the constants are being created as expected in both versions, but return is indeed not being passed back to the caller as expected in the php5 configuration.
In my code, I use several libraries and use and the following mechanic to keep an entire file from being included again in subsequent require calls:
Code:
if (defined("_{FILENAME}.PHP")) { return; };
define("_{FILENAME}.PHP", "1");
For some reason this is being ignored and the old "Cannot redeclare" error occurs for files that are only included once in php4. For testing, I used the function_exits call to conditionally include the first function and the next function will then cause the error (none are system function names or even remotely reserved). Adding this code to hundreds of functions isn't very smart either when the entire file should not be executed again.
What's changed in php5 that causes this defined/define mechanic to unexpectedly fail? What needs to be changed to fix this?
NOTE: I was able to reproduce this error by requiring FileB and FileC in FileA, when FileC also requires FileB. I used the define/defined mechanic in all files with the appropriate values. I confirmed, with get_defined_constants, that the constants are being created as expected in both versions, but return is indeed not being passed back to the caller as expected in the php5 configuration.