Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69672 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28112 invoked from network); 18 Oct 2013 12:15:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Oct 2013 12:15:26 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.178 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.223.178 mail-ie0-f178.google.com Received: from [209.85.223.178] ([209.85.223.178:60240] helo=mail-ie0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/B0-23638-A5621625 for ; Fri, 18 Oct 2013 08:15:23 -0400 Received: by mail-ie0-f178.google.com with SMTP id to1so8264482ieb.37 for ; Fri, 18 Oct 2013 05:15:20 -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 :cc:content-type; bh=nxPW1C78c55pk5Ou81WT0GgfUTXPPDQy7VorMu7mvIc=; b=Ov23kN0LBmN/U+rX+q7hKT8PNDLMtXhgpxB4VtvKm4RjnWIxIdfMG1mfjRvd6sK1Ui BMIz134aBxIFMaDnkCPMKpZiVadkChK2MiZ2gZ5pN4SLZ7coBrzokKa+pLsVTOt7VAdG gFT60AgBVwHJpydDVuJqlULBehiik25yXdBpN79eGOBd3EGTSYAap9teFDl6VSmXaXEs Bu7JOR7NHxx5SCnt17luT5HT8ip8+hKdLjUF/NxtasnPikY98sRUD2kyUVHfTGZnve9G KcKmKh6V8HPdAEz18sWMpyFY2gIKHkKW2VdHQevtdi0x7RLuuhf6hkZPsh03iX/4SWhd hblw== MIME-Version: 1.0 X-Received: by 10.50.97.7 with SMTP id dw7mr2529754igb.2.1382098519986; Fri, 18 Oct 2013 05:15:19 -0700 (PDT) Received: by 10.50.73.42 with HTTP; Fri, 18 Oct 2013 05:15:19 -0700 (PDT) In-Reply-To: References: <525FC834.4060501@php.net> <1534105.bNC2os93J1@rofl> <525FDAC3.6060103@php.net> <5260D11C.90406@php.net> Date: Fri, 18 Oct 2013 14:15:19 +0200 Message-ID: To: J David Cc: Joe Watkins , PHP internals Content-Type: multipart/alternative; boundary=047d7b10c85354194104e902e3a5 Subject: Re: [PHP-DEV] Assertions From: tyra3l@gmail.com (Ferenc Kovacs) --047d7b10c85354194104e902e3a5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Oct 18, 2013 at 1:35 PM, J David wrote: > On Fri, Oct 18, 2013 at 2:11 AM, Joe Watkins wrote: > > You have been provided very good rationale for the use of exceptions to > > handle failed assertions, we'd all be grateful if you could stop > derailing > > the conversation. > > Wow. Well, if you speak for everyone on this subject then go ahead > and implement it. Break all existing code everywhere that uses > assert() and catches all exceptions. > > But: > > On Thu, Oct 17, 2013 at 6:51 AM, Julien Pauli wrote: > > However, there is always the debatte about if a Core feature should thr= ow > > an Exception or generate an error. > > On Thu, Oct 17, 2013 at 7:45 AM, Sebastian Krebs > wrote: > > Actually if an assertion fails it means, that the application is totall= y > > broken and cannot get recovered. The use case you describe is more like > > "validation". > > This means, that even if it throws an AssertionException, when you are > able > > to catch it and recover the process, it means, that "assert" was the > wrong > > choice > > On Thu, Oct 17, 2013 at 8:01 AM, Michael Wallner wrote: > > I tend to see it the same way. I think PHP's assert is derived from > > C's assert, where ASSERT(3) says: > > > > "... assert() prints an error message to standard error and terminates > > the program by calling abort(3) if expression is false ..." > > > > Where the important part is "terminates the program". > > On Thu, Oct 17, 2013 at 5:42 PM, Rowan Collins > wrote: > > Reading through the discussion, I think this point may deserve more > > prominence: the problem with throwing an exception is that it is possib= le > > (and probably quite common) to have a catch block which catches *all* > > exceptions. Throwing an exception from assert() tangles up any handling > you > > did want to do for failed assertions with the presumably rather differe= nt > > handling you want to do for runtime exceptions. > > are you sure you speak for "all" and that merely expressing an > dissenting opinion is "derailing the discussion?" > > The feature you want is a useful new feature. The only feedback I am > offering you is to please consider adding it without breaking existing > features, for example by calling it "expect" or "validate" instead of > "assert." The word "assert" is not innately magic. Put "see also > 'expect'" in the documentation of assert and if your functionality is > truly better in all cases, people will naturally move from assert to > expect and eventually maybe assert can be deprecated if PHP is really > such a high-level language where it is not appropriate to have. The > only effect of calling this new functionality "assert" is to break > existing code. > > Not to mention that since this approach does not break BC, doing it > this way may allow the implementation of this feature sooner from a > release standpoint. > > Likewise, if you separately want to enhance the diagnostic value of > the existing assert functionality without breaking existing code, that > would also, I believe, be most welcome. But I don't pretend to speak > for all so I cannot say for sure. > > If your response is "No, you are wrong because I say so," then so be > it. You may rely on my lack of further participation in the > discussion, per your request. > > Thanks! > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Hi, Personally I think that your argument was solid, and I'm fairly sure that there are a bunch of code out there with your usecase: try{ // call a bunch of functions, which in turn calls a bunch of functions, etc. // where one of the functions uses assert() } catch(Exception $) { // report some generic error somewhere, or retry the calls a couple of times before bailing out // or do nothing, or throw a different exception with or without setting the previous exception to it } those kind of code would potentially swallow/silence the assert violation or potentionally show a different error scenario what really happened, and leave the developer confused how can he see that kind of error when the same code works in production (where the assertions don't run). using exceptions would also be less flexible than the current solution, where you killed assert_options, so introduced a BC break for everybody using that. I also agree that maybe the new one should be added instead of replacing the current(hence keeping BC), and later (when we have some feedback, and maybe extended the new way with some of the old options) can decide to deprecate the "old" assert infrastructure. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --047d7b10c85354194104e902e3a5--