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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:11:42+00:00 2026-05-14T21:11:42+00:00

I am still looking for a way to phrase it properly (I’m not a

  • 0

I am still looking for a way to phrase it properly (I’m not a native speaker…).

So I have this class SQL which implements the singleton pattern (for obvious reasons) and I also have this function, checkUsr(), which queries the database using one of SQL‘s methods.

Everything works fine as long as I don’t call checkUsr() from within the SQL class. When I do so, the scripts just exits and a blank page is displayed – no errors are returned, no exception is thrown… What’s happening? And how do I work around this problem?

EDIT:

some code here:

class SQL
{
  public static function singleton()
  {
    static $instance;
    if(!isset($instance))
      $instance = new SQL;
    return $instance;
  }

  public function someOtherFun()
  {
    checkUsr();
  }

  public function tryLoginAuthor( $login, $sha1 )
  {
    // SQL query
  }
}

function checkUsr()
{
    if (!isset($_SESSION['login']) || !isset($_SESSION['sha1']))
        throw new Exception('Not logged in', 1);
    $SQL = SQL::singleton();
    $res = $SQL->tryLoginAuthor($_SESSION['login'], $_SESSION['sha1']);
    if (!isset($res[0]))
      throw new Exception('Not logged in', 1);
}

So the problem occurs, when I call checkUsr from within the SQL class. It does not, however, happen when called from some other class…

  • 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-14T21:11:43+00:00Added an answer on May 14, 2026 at 9:11 pm

    You have to turn on error_reporting, to see the error messages by php, otherwise you will get the blank page you describe.
    At the top of your index.php file, include these:

    ini_set('display_errors', true);
    error_reporting(E_ALL | E_STRICT);
    

    Don’t forget to turn it off in your production machine, this is only for development.

    You have declared the variable $instance, as static inside the function, instead of inside class. These are two completely different things. See the usage of static variables here, and see the usage of a static class property here. You need the latter, so change your code to this:

    class SQL {
        static $instance;
        public static function singleton()
          {
            if(!isset(self::$instance))
              self::$instance = new SQL;
            return self::$instance;
          }
    ...
    
    }
    

    Implementing a SQL class, or any kind of database access as a singleton is a very bad idea, it’s going to bite you very hard in the long run. If it turns out that you
    need to support another database, like you need to pull information from a forum, that is in a different DB than your site, you will have serious problems.

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

Sidebar

Related Questions

I was looking at this code of a sieve of eratosthenes but i still
I still have issues reading UML diagrams. Just looking at the Builder pattern http://en.wikipedia.org/wiki/Builder_pattern
This is related to another Delphi-version question but still different; I'm looking for a
I'm still looking for a way to change the summary of a ListPreference according
Similar questions have been asked on SO, but I am still looking for a
Please if anyone knows the answer, I´m still looking for 3 days and nothing..
Been looking through other answers and I still don't understand the modulo for negative
still a bit of a n00b on SharpSVN, I'm looking to get some simple
Looking at the docs of libavfilter it doesn't seem to be possible, but still,
I've done some looking around, but I'm still confused a bit. I tried Crockford's

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.