Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41957 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52301 invoked from network); 17 Nov 2008 08:16:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2008 08:16:18 -0000 Authentication-Results: pb1.pair.com header.from=kalle.php@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=kalle.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.220.156 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: kalle.php@gmail.com X-Host-Fingerprint: 72.14.220.156 fg-out-1718.google.com Received: from [72.14.220.156] ([72.14.220.156:54989] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/FE-39815-05821294 for ; Mon, 17 Nov 2008 03:16:17 -0500 Received: by fg-out-1718.google.com with SMTP id 16so2138996fgg.23 for ; Mon, 17 Nov 2008 00:16:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=vRMwNGPKoBGS8xefMU0QbjYGAzWdmHWLgcYnPDhZfDE=; b=WfHAG3WKfK9cz+6jRFv0dO70ZbGrm+2BQ6Y7vvFFGihvwT5K/+L0zsiDe9InyTVIeO ogwZD+1xI6ICBOa4Sxnaj+0Zhkp2UxqrzfF+yBwmD66SUpZ8fJLLD3bJkNutmSBL18br fuyuT7LnEL5etGxhmJZW2L/iQJb7L6UL0YdzI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=iB/l74u+SxqA1aZLAXMz7MW58t8UdseEsq4WH8hewKCMUQRPlcnBmhMignBFBf5pcG w1SIDAgBlCW0YEWh3nBPuspIyilVZJtR8mEfEmvTDdJWj28iOx9YVipkwrYye5U37wI7 Q/VNSCYAn30yAl9D0YvDIxbU/BA9h4Kh7BjI8= Received: by 10.187.212.14 with SMTP id o14mr419810faq.23.1226909773974; Mon, 17 Nov 2008 00:16:13 -0800 (PST) Received: by 10.187.218.19 with HTTP; Mon, 17 Nov 2008 00:16:13 -0800 (PST) Message-ID: <2dedb8a0811170016i74ce2faepef092a1302920202@mail.gmail.com> Date: Mon, 17 Nov 2008 09:16:13 +0100 To: "Christopher Vogt" Cc: internals@lists.php.net In-Reply-To: <28.8E.39815.8C421294@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <28.8E.39815.8C421294@pb1.pair.com> Subject: Re: [PHP-DEV] Fatal error: Call to a member function on a non-object From: kalle.php@gmail.com ("Kalle Sommer Nielsen") Hi 2008/11/17 Christopher Vogt : > 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