Home > PHP, osCommerce > PHP 5.2.0 Compatibility

PHP 5.2.0 Compatibility

PHP 5.2.0 was recently released which “includes a large number of new features, bug fixes and security enhancements” to the PHP 5.x series. The PHP Group also published an upgrade guide for existing PHP 5 users that documents the (incompatibility) changes the new release brings.

osCommerce 2.2 Milestone 2 Update 060817 works fine with PHP 5.2.0 (with register_globals and register_long_arrays enabled).

There is however one change that 5.2.0 brings in that causes osCommerce 3.0 Alpha 3 to produce a PHP FATAL error in the sessions implementation, specifically when the session data is stored in the database (by default for osCommerce 3.0).

This is due to a change in session_set_save_handler() where the “write” and “close” handlers are called after objects have been destructed.

As the sessions implementation in osCommerce 3.0 is done in a class/object, writing session data and closing the session are no longer possible as the registered object would be destructed and no longer exist to perform those duties.

The proper solution here is to use session_write_close() in the destructor of the osC_Session class:

class osC_Session {
...

function __destruct() {
session_write_close();
}
}

As __destruct() is a PHP 5 feature only, an alternative solution is needed for PHP 4 compatibility (the minimum requirement for osCommerce 3.0 will be PHP 4.1), and that is to register session_write_close() as a shutdown function:

session_set_save_handler(array(&$this, '_open'),
array(&$this, '_close'),
array(&$this, '_read'),
array(&$this, '_write'),
array(&$this, '_destroy'),
array(&$this, '_gc'));

register_shutdown_function('session_write_close');

This has already been reported at our new Issue Tracker and has been fixed at r1107.

Categories: PHP, osCommerce Tags: ,
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.