Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34288 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80482 invoked by uid 1010); 31 Dec 2007 11:28:58 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 80467 invoked from network); 31 Dec 2007 11:28:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Dec 2007 11:28:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=thrthr@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=thrthr@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.198.190 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: thrthr@gmail.com X-Host-Fingerprint: 209.85.198.190 rv-out-0910.google.com Received: from [209.85.198.190] ([209.85.198.190:8104] helo=rv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/49-02434-952D8774 for ; Mon, 31 Dec 2007 06:28:58 -0500 Received: by rv-out-0910.google.com with SMTP id k15so3637353rvb.23 for ; Mon, 31 Dec 2007 03:28:23 -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:mime-version:content-type; bh=AGubmmIzsF+46VlxFCl27aY0/NJPi2AtUT09FQVSJrg=; b=C+uaaoGRB81e1yXFhvOKEHW5dsHznEuJ9dYqSEXpyrq4OwptYTLnlr2/UbsArOlU61H+UMHzoIZJ+Pw5EZBvjKgqwsHpClmClGNBKNvqxSsXJo+WLx0TiIswN8lVIYVbE+s/NID1ULbnXs5Bc+ewGIS0X+fbUwGHUHIaBdpMWMo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=c/0q/7H4GO6VHTgqLCdRX7cSn6ueU4oJ7jcthlw8mBluZyMGSDDQa3UXyb4vv8BLu5LcnzYvd47hPng0WWI2IOySPG7uFfEW6TvfNu4GwCFfWq3YHGgXtCsHvg4dc8mfGKtZIDHiDbUZSXQjerjLoDOiYZ1bwoFhrHksiDsDA1w= Received: by 10.142.105.14 with SMTP id d14mr3554138wfc.67.1199100503158; Mon, 31 Dec 2007 03:28:23 -0800 (PST) Received: by 10.142.127.3 with HTTP; Mon, 31 Dec 2007 03:28:23 -0800 (PST) Message-ID: <8697e5310712310328n4c0fa235wb5654178028942bd@mail.gmail.com> Date: Mon, 31 Dec 2007 12:28:23 +0100 To: internals@lists.php.net MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_20100_23360661.1199100503128" Subject: Exceptions instead of Fatal Error when calling non existent method? From: thrthr@gmail.com ("=?ISO-8859-1?Q?Fredrik_Holmstr=F6m?=") ------=_Part_20100_23360661.1199100503128 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi! I've never posted on internal before, but I've been a long time reader of it. I've been using PHP for a long time, I think it all started back in 2000 sometime, anyway - this is hardly a place to put my entire php biography up for show, so I'll jump right to the action. Ever since PHP5 and the much improved object model (exceptions, and what not) there has been one thing missing (at least for me) the whole time. When you call a method (and function, but this doesn't really matter from an OO perspective) on an object that does not exist, you get a "Fatal error: Call to undefined method Foo::bar() in C:\www\index.php on line 4". What I would like to argue/request is that there should be a way to get an exception thrown when you call a non existent method on an object, since it's not possible to catch E_ERROR with a user defined function using set_error_handler() I can't see anyway to accomplish this in the current implementation? Why do you want this? To allow for "true" duck typing (which I think fits good into PHP's dynamic nature) without having the risk of your application running into fatal errors and now having to use if(method_exists($obj, $method)) on every call I want to make. I've come up with a couple of suggestions on how this could be implemented, but I'm not very good with the inner workings of php / zend engine (I've read parts of Saras book, but that's about it) so I don't know how hard (or easy) any of these suggestions would be to implement: a) Change the error raised when running into an unknown method call into it's own type that is fatal if not caught by an user defined error handler? b) Change the error raised to E_WARNING c) Change the error raised to E_RECOVERABLE_ERROR which as far as I can make out is possible to handle with a user defined error handler? d) Make the engine throw an exception of a special type when an unknown method is called, possibly provide an php.ini-setting so you can toggle between the old (E_ERROR) and the new (UnkownMethodException) to not break BC? Thanks for reading my message, regards Fredrik. ------=_Part_20100_23360661.1199100503128--