Jump to content

Fatal error:


raydona

Recommended Posts

Hi,
I have something like shown below:
 

class Anon
{
$_dddd = null;
.......
public function _construct()
{ $this->_dddd = DB::getInstance();
}
$check = $this->_dddd->get(.......)
.......
}
    class DB
    {
       private static $_instance = null;
       private $_pdo, $_query, $_error = false, $_results, $_count = 0;

       private function _construct()
       { try{ 
             $dsn = sprintf( "mysql:host=%s;dbname=%s;", 
                                Config::get('mysql/host'), 
                                Config::get('mysql/database')
                            );
             $this->_pdo = new PDO($dsn, 
                                   Config::get('mysql/username'), 
                                    Config::get('mysql/password')
                                );
        } catch(PDOException $excp){ 
            die($excp->getMessage());
        }
    }

       public static function getInstance()
       { if(!(self::$_instance))
         { self::$_instance = new self(); 
         }
         return self::$_instance;
       }

$_dddd is holding a SINGLETON object.
When I do above I get following message:
Fatal error: Call to a member function get() on a non-object

Can anyone point out the mistake(s) in my code and how to rectify it. Will be very grateful.

Link to comment
https://forums.phpfreaks.com/topic/291217-fatal-error/
Share on other sites

The first snippet isn't even syntactically valid, so how are we supposed to help you with this? Give us the real code, not some fantasy code you made up.

 

Also note that “__construct” has two underscores. You have only one, which means this is a normal method which doesn't get called anywhere.

Link to comment
https://forums.phpfreaks.com/topic/291217-fatal-error/#findComment-1491805
Share on other sites

If I would translate the error message to 'human error message':

You tried to call the method 'GET' on a variable... Normally, when you call a method with ->, it's for an object. But you tried to call it on a variable that is not an object.

It's hard to tell because your code isn't complete, but it probably comes from this line:

$check = $this->_dddd->get(.......)

It's the only place where you have a 'get'... My guess would be that _dddd is still null. And since 'null' is not an object and you try to call GET like if it was, that's probably why you get that error.

Link to comment
https://forums.phpfreaks.com/topic/291217-fatal-error/#findComment-1491817
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.