Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62452 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22602 invoked from network); 24 Aug 2012 16:49:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Aug 2012 16:49:09 -0000 Authentication-Results: pb1.pair.com header.from=alex.aulbach@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=alex.aulbach@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: alex.aulbach@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:47975] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/A0-30159-480B7305 for ; Fri, 24 Aug 2012 12:49:09 -0400 Received: by vcbgb30 with SMTP id gb30so2696499vcb.29 for ; Fri, 24 Aug 2012 09:49:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=GG8uv9bgcbdo7d2ROAtJCFZuhNyDj+OrijqK/YHzb0k=; b=KycnBIOvZZCnh6dDCoh9NlRwhe57/TF9GZUYNka4YzvSa2AmAxgqV5+UXtpCU3AjhY A+BDQMk0oPbg/HZ40X41dC7o0wIPOyUo3qcpRG30H8tSeoXjz4L94CnGheJG0/EMT6pE EE3SwgWzj9dOhukA6TKr0CjT3wkY16ZFPGG0W1mES3qihFI/KXLrfb5p7l8Du44CfkR+ 7Eqjqyckn66RI3aDNITlNWM/ulPE6R1ScYcvO8d8mgTdEKidxYEGJmFHR+g5esWv1u22 L+junJm5Rm7uhsZxmgpq8uku2bSjLiH71FwBe0Xo1BRig1GVSF9uHM06N1mcncqTuwRJ SaiQ== MIME-Version: 1.0 Received: by 10.52.37.100 with SMTP id x4mr4421343vdj.56.1345826945966; Fri, 24 Aug 2012 09:49:05 -0700 (PDT) Received: by 10.58.133.229 with HTTP; Fri, 24 Aug 2012 09:49:05 -0700 (PDT) In-Reply-To: References: <3E3A531D90FC43B8B7E9CDD37F1EEE40@pc> Date: Fri, 24 Aug 2012 18:49:05 +0200 Message-ID: To: PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Error handling brainstorming From: alex.aulbach@gmail.com (Alex Aulbach) 2012/8/24 Nicolas Grekas : >> ** >> The overall mood seems to be that since PHP has an error handler, everyone >> is free to handle errors any way they want. >> 2) When everyone starts handling errors in their own way with error >> handlers, you can't reliably use third party code. You are in your own >> universe. >> > > I think that's the main point that makes any change to the way PHP > currently handles errors difficult: > > The current behavior is to continue the execution flow (except for fatal > errors of course) whereas an exception always breaks it. Throwing an > exception, either in a custom or in a new internal handler, introduces a > major portability + backward compatibility issue. I think we should talk first over the general handling and then go into the details (how to handle the different types of errors/warnings etc.) Maybe I repeat some things. What do we want? A) Handling errors with exceptions instead error-handler B) handling warnings/notices in some way. That are 2 completely different things... For A: Errors (something which stops execution) could be just handled as an exception. I see no problem with this: If not handled, they behave like now. For B - the warnings etc. - I suggest something like this: // This is pseudocode: abstract class WarningAbstract implements Exception { public function __construct() { error_log($this->message()......); unset($this); // I just want to say, that the exception is destroyed in any way and so not handled any more } ... } // A warning looks like this - this is created by PHP for example when turning on E_WARNING in php.ini class Warning extends WarningAbstract { } // and when created it does this: if (class_exists('Warning')) { $warning = new Warning(); if (isset($warning)) { throw $warning; } } Logically, when the exception is created the constructor is called. In this example (by default) PHP could handle a warning etc. (write something into a error-log) and then "destructs itself", to stop the handling. (Of course this doesn't work now, when unseting myself the object is not unseted; I wrote this code only so that PHP-programmers could understands what I mean.) [Not so important: could be configured like now. If E_WARNING is turned on in the php.ini, PHP creates the default handler for this class itself. If not, the class doesn't exists and so nothing happens. Or I create my own Warning class, and implement my own way to handle the warnings.] This has the big advantage, that we don't need to care about the mentioned different handling of the different type of errors (see above: A, B). I think it is important, that the way how it is done is for every kind of error the same. Now the details: A file-error is defined abstract class FileHandlerWarningAbstract extends if exists Warning // of course "if exists" is no PHP - just to explain that it should work as a "hint" for the compiler to create the "hierarchy" { } The code to create the exception needs to recursively look up: If no FileHandlerWarning exists it must know the "hirarchy of it's abstract" (in this case the Warning) and look if that class exists. And so on. So you can handle file-errors different from all other warnings without try/catch everything. Not perfect for now, and I think a little bit too complicated, but this is a brainstorming. -- Alex Aulbach