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 7066775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:07:16+00:00 2026-05-28T05:07:16+00:00

I am having problem with implementing custom session handler in php. The code: http://pastebin.com/9QV9f22Q

  • 0

I am having problem with implementing custom session handler in php.
The code:
http://pastebin.com/9QV9f22Q

I initialize this once in my frameworks bootstrap, after I have connection with db:

require_once 'DbSession.php';
$session = new DbSession();
session_start();

But then I can’t view my page. Firefox gets 302 Status with “Server not found” error. Firebug says that content is 5k long, but I can’t view the page.

Log after one reload:
http://pastebin.com/JYe14nGR

I wonder why it still “loses” that created DbSession instance. Do yo have any ideas? TIA

  • 1 1 Answer
  • 0 Views
  • 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-28T05:07:17+00:00Added an answer on May 28, 2026 at 5:07 am

    Your code is based on a false premise: that you can return a different object from a PHP constructor. Quite the opposite: PHP entirely ignores the return value from a constructor.

    Here’s what’s actually happening.

    When your code calls:

    $session = new DbSession();
    

    the $firstTime == false check runs, meaning getInstance() gets called.

    getInstance finds no existing instance, so it calls setup().

    setup() calls new DbSession() again, this time passing in the argument preventing another call to getInstance(). It creates the object, registers it as the session handler, and returns it.

    getInstance shoves the object in a static variable, and then returns it to the original constructor call. The original constructor call then drops the existing object on the ground and returns a brand new copy of itself.

    You can fix some of this insanity by never instantiating the object outside of setup/getInstance(). Try making the constructor protected and only ever calling getInstance().

    However, none of this explains why the code is malfunctioning for you. In fact, we can’t explain it either. We’re missing all the rest of the code, including what database adapter you’re using, what ORM you’re using (or even if you are using an ORM, your class and method names suggest it), what framework(s) might be involved, etc.

    Try cutting all of the actual database touching from the class. Just write files on disk. Get that working first, then introduce the database layer. Chances are that your error will become obvious at that point.

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

Sidebar

Related Questions

I'm having a problem implementing custom 404 error pages on my Windows/IIS/PHP webhost. Whenever
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I am having a specific problem implementing a parametrised class Parameter, but this is
So, I'm having some issues here implementing this math problem in C++. Let's say
Hi I'm having a problem implementing this method. I have added using System.Management but
I'm having a headache implementing this (awful) pseudo-java code (I wonder: why the hell
I'm having a problem implementing a bi-directional parent/child relationship using hibernate 3. The parent,
Problem: I am having trouble implementing a recursive image lazy load in all relevant
Am having a number of problems implementing the code from the Washington Post site
I am having a really strange problem implementing Java REST service. I am trying

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.