Fatal error: Call to a member function on a non-object

From: Date: Mon, 17 Nov 2008 08:01:09 +0000
Subject: Fatal error: Call to a member function on a non-object
Groups: php.internals 
Request: Send a blank email to internals+get-41956@lists.php.net to get a copy of this message
Hej, I use PHP 5.2.6. I am refactoring some code to use more object-orientation. I encounter a problem, where the new object-oriented version results in a fatal error, where the old array-oriented version didn't. I fetch records a database. Sometime it happens that a record does not exist anymore. Let's assume it's a user, then $user will be NULL. echo $user['fullname']; // no error at all, $user['fullname'] === NULL Shouldn't this at least trigger a Notice? echo $user->get_fullname(); // Fatal error I agree this should trigger an error, but a "Fatal error" is a little too much, I think. It terminates the script leaving the html-document incomplete. I would prefer a "Warning" and NULL instead. Is there any reason against it? Best regards Christopher

« previous php.internals (#41956) next »