php5 migration
I recently upgraded my local testing server to php5. Right off the bat I experienced two differences from my previous php4 setup.
First, for the ‘I need a solution quick’ people.
- Don’t use $PHP_SELF in your forms & links. Use $_SERVER[’PHP_SELF’]
- To get error reporting back on. Search your php.ini for the ‘Error handling and logging’ section and uncomment (by removing the semi-colon) the type of error reporting you want. (eg. error_reporting = E_ALL)
The details
I’ve always used <form action = “<?php echo $PHP_SELF;?>”> in my forms to have them submit to the same page they were on. After switching to php5 I got this error:
<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>C:\Server\htdocs\darrenfauth...
Php5 ships with register_globals = off. Actually, according to the php documentation register_globals have been off since php4.2.0. Since I was running 4.3.11, I must have turned them on and forgotten about it.
As it states in the docs: Internal variables that are defined in the script itself get mixed up with request data sent by users and disabling register_globals changes this.
Just last week, I had a 3-tiered user level intranet site I was programming go wacky with user levels mysteriously changing. I finally realized it was the use of register_globals = on that was allowing my script variables to be changed via my forms. Having register_globals = on also brings with it a variety of security risks. Needless to say, I’m glad to have been introduced to the problem now.
The second change was the level of error reporting.
Php5 ships with error_reporting NULL. Or more simply, no error reporting at all. Something goes wrong in your script, all you see is a blank white page. Not real useful for debugging on your testing server. You can read all about the php error handling here.
If you run into this problem, here is the solution. Open your php.ini file and search for:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; error_reporting is a bit-field. Or each number up to get desired error
; reporting level
; E_ALL - All errors and warnings (doesn't include E_STRICT)
; E_ERROR - fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string)
; E_STRICT - run-time notices, enable to have PHP suggest changes
; to your code which will ensure the best interoperability
; and forward compatibility of your code
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
;
; Examples:
;
; - Show all errors, except for notices and coding standards warnings
;
;error_reporting = E_ALL & ~E_NOTICE
;
; - Show all errors, except for notices
;
;error_reporting = E_ALL & ~E_NOTICE | E_STRICT
;
; - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
; - Show all errors, except coding standards warnings
;
error_reporting = E_ALL <------- I removed the ';' from mine right here
Simply remove the semi-colon from in front of whichever error reporting level you want. You’ll have to restart your server to effect the change.