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

  • Home
  • SEARCH
  • 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 662615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:23:53+00:00 2026-05-13T23:23:53+00:00

I have this class that have a function to load other classes and create

  • 0

I have this class that have a function to load other classes and create instances.

if you used this class like this:

    $test = new test();
   $test->load("email");

it works perfectly as expected
but when using session_start();

$test = new test();
session_start();
$test->load("email");

an error is created and nothing else is there:
PHP Fatal error: Call to a member function load() on a non-object in bla bla bla

the class used with session_start:

<?php

 class test
{


 function load($class){

  static $objects = array();

  if (isset($objects[$class]))
  {
   return $objects[$class];
  }

  require('libraries/'.$class.'.php');

  $name = 'ext_'.$class;

  $objects[$class] =& new $name();

  $this->$class = $objects[$class];

  return $objects[$class];


 }

}


$test = new test();

session_start();

$test->load("email");
?>

and here is libraries/email.php:

<?php


class ext_email
{

 function ext_email(){
         echo "email is working";
 }

}

?>

can you please advice what is wrong with this? a way to improve the load function?
this thing works on some installations of apache and fail to work on others. depending on some configs that I don’t know what exactly is it..

I want to be able to do the following:
$test = new test();

session_start();

$test->load("email");

thanks a lot in advance

  • 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-13T23:23:54+00:00Added an answer on May 13, 2026 at 11:23 pm

    Maybe you have some variable named test in $_SESSION, and have register_globals enabled ?

    In which case, the $_SESSION['test'] variable will be created as a global $test variable by the call to session_start(), overridding any existing $test variable of your script.

    This would also explain why this is happening on some servers and not some others : register_globals is Off by default — and has been for many years, but some hosts keep it enabled 🙁

    (When people say register_globals is evil, it’s not without a good reason…)

    For more informations, you can read the [Using Register Globals][2] page of the manual — there is even a paragraph about `$_SESSION` and some problems that `register_globals` can cause.

    Now, on how to fix this… Well, I suppose the fastest way would be to make sure that `session_start()` is called before you set `$test` to what you want it to be :

    session_start();
    $test = new test();
    $test->load("email");
    

    This way, even if a $test is created because of register_globals, your variable will override it — and the last one is the one that’s right ^^

    But the best solution would be to turn register_globals Off : that’s a reliquate from the past… That should probably never have existed 🙁

    (There are some bad things in PHP ; that’s one of them, in my opinion)

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is there some kind of magic going on in the… May 14, 2026 at 9:03 pm
  • Editorial Team
    Editorial Team added an answer I think one of the better ways to do this… May 14, 2026 at 9:03 pm
  • Editorial Team
    Editorial Team added an answer The value of the length property of any array, is… May 14, 2026 at 9:03 pm

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.