Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107609 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80958 invoked from network); 21 Oct 2019 19:40:29 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 19:40:29 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id B12682D19AB for ; Mon, 21 Oct 2019 10:26:10 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Mon, 21 Oct 2019 10:26:10 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id y81so9503955qkb.7 for ; Mon, 21 Oct 2019 10:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1lBepvdDEK5dYkQleJHEfQY8DxOh8k7A3AVVP4K8o3w=; b=KT837u9eBiN8l2MgfoGyV+yuJOcwazOaEGOtegTBxu4nYiv3awy6pK+PVoI0bwY4NW AXHwMqSezljB4TyPUhvuMByZdJzPxL+sb7Pfbg4E40Wt5MwjlqW95cP5OM+w2T1k51gh DfHq1FF7phPCXuUwOjyKYFs1YmdjR57C5gbfJpxrBSpYjAv6/ByPBUeXCBvtrKZdw+pV gTdfIXBBwnw1IaMCulEnLesD6m4iQZpRF4/5VFJFi5cO7qZUF0bEe8EorBT6mVI6V4u7 uGgzyqmrD842Wxpw3npTN+o2KR5Dx6lYwqRZa+clWa7+KyEL3gIt66Ra/Np6aDO23lf+ 10/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1lBepvdDEK5dYkQleJHEfQY8DxOh8k7A3AVVP4K8o3w=; b=Cspchz1YWUxxv8twFDtP4WnqrL8O2Hov6mZ/GSrDZDOaIB+UgWGqwMyDsMzgemLLVO wa+LOrhXKquEog5fh0SRcivpOkbBJCLw5k7f8SlZrxXdAGY0fPvsqhGw6h74yE19G8Fu Oy+GSZWnJX6M4+fZ+9ZrdCgwJ+7bFY1nmpZOE5OKJJlhAERHicB2pCvOnZ5Qiay6ASHk pGfpZZPq79wDMqxM4VN8Q2Dylb4E0Pu+eOhaTdphylzZZnWwYPjosWAeU4ciWmGc6W9S 2ykWtcAUDFThwjo/2bS/fw3m5/2Ycosz4MfotDHiA3mLF3Q5GIhPNZKimBcdxOJLLbQg f6Wg== X-Gm-Message-State: APjAAAVHPRPz+0WkTqrIkJjPfp8Au4h1U4X1uMLxhg81oFyJF63urQ71 fa5Ne5PpOCzVmS4KUg+Iiw8TNjG10OA= X-Google-Smtp-Source: APXvYqx0sYe8xDGF4Zdg2CnlFkwLO+Ce6lFpr8TdlrzzbzpdTS2rFMlcjKVTluWE3JSFCib9rhH7BQ== X-Received: by 2002:ae9:ea17:: with SMTP id f23mr14572366qkg.49.1571678769021; Mon, 21 Oct 2019 10:26:09 -0700 (PDT) Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com. [209.85.160.169]) by smtp.googlemail.com with ESMTPSA id l129sm9537480qkd.84.2019.10.21.10.26.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2019 10:26:07 -0700 (PDT) Received: by mail-qt1-f169.google.com with SMTP id c17so19201009qtn.8 for ; Mon, 21 Oct 2019 10:26:07 -0700 (PDT) X-Received: by 2002:aed:3847:: with SMTP id j65mr26105971qte.124.1571678767507; Mon, 21 Oct 2019 10:26:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 21 Oct 2019 19:25:56 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: text/plain; charset="UTF-8" X-Envelope-From: Subject: Re: [PHP-DEV] Reclassifying some PHP functions warning as exceptions From: andreas@dqxtech.net (Andreas Hennings) I agree with the distinction described by Nikita. There are definitely cases where a special return value is still the best option. In addition I would say in some cases it can be useful to have both versions available: One that returns FALSE or NULL, another that throws an exception. This is for cases where it is up to the calling code whether a failure is considered "exceptional" or not, or whether the calling code wants to check the error in place or have it bubble up the call stack. Whether something is exceptional can be a matter of expectation, and previous knowledge within the calling code. Take e.g. the reflection API: - If we call "new ReflectionClass(self::class)", we assume that the class exists. If it does not, this would warrant a runtime exception. - If we already checked "class_exists($class)" before, then it makes sense for "new ReflectionClass($class)" to throw an exception. We would even want a runtime exception. - If we receive an arbitrary string that matches a class name regex, we would like to have a ReflectionClass::createOrNull($class), which would NOT throw an exception, but return NULL if the class does not exist. If we provide two variations, they should definitely live in different functions / methods, instead of e.g. having a parameter to determine the failure behavior. Having two separate methods/functions allows better code verification by the IDE, and avoids false inspection warnings for "unhandled exception". Considering the BC impact, I think that providing an alternative method/function will be the best we can do in most cases. -- Andreas On Mon, 21 Oct 2019 at 18:03, Rowan Tommins wrote: > > Hi David, > > Firstly, I agree with Nikita's general rule of which Warnings should be > promoted and which need deeper thought. > > I would like to challenge one assertion in your e-mail, which is related to > that thought process: > > > On Mon, 21 Oct 2019 at 14:52, David Negrier > wrote: > > > We would be happy to promote more warnings to exceptions as those: > > - are more predictable > > - can be more easily caught / handled > > > > > I have always thought, and continue to think, that converting all Warnings > (and Notices) to Exceptions is inappropriate, because Exceptions have some > very specific behaviours, which are not always desirable: > > - They immediately jump control out of the current frame of execution. > Unless you put a separate "try-catch" around every line, there is no > "acknowledge and run next line". > - Their default behaviour if not handled is to completely terminate > whatever is happening, right up to showing a blank white screen. > > There is no general way to know whether the result of aborting execution > completely is better or worse than carrying on with unexpected values. In a > program that's not expecting it, either one could lead to data loss or > corruption. > > There are definitely places where a Warning can reasonably be converted to > an Exception; but I don't think this should be done as some kind of bulk > change. Each Warning we promote should have at least one person answer the > question "is it likely that terminating processing when this happens at > run-time will be better than flagging a Warning and returning a defined > value?" > > Regards, > -- > Rowan Tommins > [IMSoP]