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

From: Date: Mon, 17 Nov 2008 08:16:13 +0000
Subject: Re: Fatal error: Call to a member function on a non-object
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-41957@lists.php.net to get a copy of this message
Hi 2008/11/17 Christopher Vogt <christopher.vogt@rwth-aachen.de>: > 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? I personally don't really mind it, as you got the instanceof and typehinting to check for whenever a variable is an object, so I would say its more of a user design issue. Fatal errors just requires you to refactor your code so your code shouldn't emit such things which I'm alright with. > > Best regards > > Christopher > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Kalle Sommer Nielsen

« previous php.internals (#41957) next »