Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Jan 2005
    Posts
    1,649
    Plugin Contributions
    2

    Default workaround for php5.2 issue

    I saw at least another thread discussing this, but none under "code matters" (and none containing a good solution IMO), and I wanted to make sure this is read by the right people so I decided to submit a bug report.

    Call to a member function Execute() on a non-object in ...includes\functions\sessions.php on line 61
    According to http://www.php.net/session_set_save_handler, session "Write and Close handlers are called after destructing objects since PHP 5.0.5". Why this was not a problem in ZC and other scripts between PHP 5.0.5 and 5.2 I don't know, and I can't say I'm much wiser after skimming through the PHP changelog either because some of the bugs that were fixed in PHP5.2 (that could be related to this issue) were not well described.

    Anyway, the problem is that ZC won't work properly with custom session handler (db) in PHP5.2, and the reason seems to be (assuming I've got the facts right) that objects are destroyed before the session is written, as stated in the PHP manual and quoted above. In other words, the $db object, which is needed by the custom db session handler, won't be available to the session save and close handlers.

    I saw another workaround for PHP5.2 mentioned somewhere in these forums that instantiated a new $db object in the custom session write handler, but that's not necessary if the session is written and closed before objects are destructed, and that can be accomplished by calling session_write_close() at script shutdown, ie.
    Code:
    register_shutdown_function('session_write_close');
    The above line should be called whenever session_set_save_handler() is called (and the session write handler makes use of objects), so I'll suggest a wrapper function.
    Code:
    function zc_session_set_save_handler ($open, $close, $read, $write, $destroy, $gc)
    {
    	if (session_set_save_handler($open, $close, $read, $write, $destroy, $gc) === false)
    	{
    		return false;
    	}
    	# write and close session at the end of script, and before objects are destroyed (required for PHP5.2)
    	register_shutdown_function('session_write_close');
    	return true;
    }
    and replace calls to session_set_save_handler() with zc_session_set_save_handler().
    Last edited by dwno; 17 Jan 2007 at 10:00 PM.

 

 

Similar Threads

  1. Where do I find the PHP5 workaround?
    By plymgary1 in forum General Questions
    Replies: 2
    Last Post: 4 Jan 2010, 04:25 PM
  2. PCI compliancy issue & php5.2.10?
    By stride-r in forum Installing on a Windows Server
    Replies: 6
    Last Post: 22 Aug 2009, 11:23 PM
  3. Workaround for Resellers/Tax Exempt
    By sarahbn in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 5
    Last Post: 26 Jun 2009, 08:13 PM
  4. Workaround for QuickBooks with two state tax amounts?
    By d0ugparker in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 15 Jun 2009, 03:03 PM
  5. Best Workaround For Multiple Coupons?
    By trackerkbc in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 1
    Last Post: 5 Aug 2006, 03:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg