Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 294921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:24:40+00:00 2026-05-12T06:24:40+00:00

I have to migrate a php4 app that uses session_set_save_handler() to php5. In php4

  • 0

I have to migrate a php4 app that uses session_set_save_handler() to php5.

In php4 everything was fine, but in php5 the callback functions cannot access the global vars anymore, which were set on the page before session_set_save_handler() was called.

In the example below the global var $g1 cannot be accessed in the session_writer() (which is passed as a callback function)

Is there some explanation for this behavior or can you give a hint on migrating sessions with callbacks from php4 to 5?

This is the pseudo code:

function session_writer($id,$vars) {
  global $g1;
  echo "g1 not defined here: ".is_object($g1);
}

global $g1;
$g1 = SomeObject(); //which is the DB connection for the session writer

session_set_save_handler($o,$c,$r,"session_writer",$d,$g);
session_start();
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:24:40+00:00Added an answer on May 12, 2026 at 6:24 am

    This is actually noted in the documentation:

    As of PHP 5.0.5 the write and close handlers are called after object destruction and therefore cannot use objects or throw exceptions. The object destructors can however use sessions.

    It is possible to call session_write_close() from the destructor to solve this chicken and egg problem.

    Essentially, you’ll have to call session_write_close() from the destructor of your SomeObject, or alternatively, do the following:

    <?php register_shutdown_function("session_write_close"); ?>
    

    Either of those solutions should force the writing and closing of the session before all objects are destroyed, allowing you to keep your original callback function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 199k
  • Answers 199k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The SortedList extends a Collection by implementing IComparer to provide… May 12, 2026 at 7:50 pm
  • Editorial Team
    Editorial Team added an answer You have misunderstood the way classes work in Python. You're… May 12, 2026 at 7:50 pm
  • Editorial Team
    Editorial Team added an answer It depends a little bit on the rest of your… May 12, 2026 at 7:50 pm

Related Questions

I have a script running on a server with PHP4 that uses DOMXML. Now
I have a legacy web application php4/mysql4 (MyISAM, db contains some cms, some user
I have a legacy web application php4/mysql4 (MyISAM, db contains some cms, some user
I have to migrate a table from MSSQL Server to MySql. The problem is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.