raydona Posted September 22, 2014 Share Posted September 22, 2014 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-objectCan anyone point out the mistake(s) in my code and how to rectify it. Will be very grateful. Quote Link to comment https://forums.phpfreaks.com/topic/291217-fatal-error/ Share on other sites More sharing options...
Jacques1 Posted September 22, 2014 Share Posted September 22, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/291217-fatal-error/#findComment-1491805 Share on other sites More sharing options...
mogosselin Posted September 22, 2014 Share Posted September 22, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/291217-fatal-error/#findComment-1491817 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.