Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94095 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97183 invoked from network); 17 Jun 2016 20:32:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2016 20:32:24 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.218 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.218 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.218] ([81.169.146.218:51140] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/5D-18862-75E54675 for ; Fri, 17 Jun 2016 16:32:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1466195540; l=5860; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:In-Reply-To:References: MIME-Version; bh=MAb9j/Bc/X2XzthpN/EP8quayNwEIUhrB/dbAUNOHvg=; b=ORl5CjSGwa/5WmZ7+KgZ0ySx1Fv82GUPs4X9wZAb/oLVrxhE74WnNMtvpqZNVp1Q4Mk tHd9TVBNJEODTQMuRvyCu86kTji8QVCIG7gbg8zYi2wZLowR0pYgu0i5SqsS42kvLBdLE Gh85iAydl+6et7VpUmFKL+aUbrWkk4C3KFQ= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtO3E6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f42.google.com ([74.125.82.42]) by smtp.strato.de (RZmta 38.6 AUTH) with ESMTPSA id R0216fs5HKWKD6e (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Fri, 17 Jun 2016 22:32:20 +0200 (CEST) Received: by mail-wm0-f42.google.com with SMTP id f126so2716886wma.1 for ; Fri, 17 Jun 2016 13:32:20 -0700 (PDT) X-Gm-Message-State: ALyK8tKt2u8XIeivDMm5S5jJKLhVY7YKASgpIHhXDHnIhoqQheZFAnQCbRmcYrPvYlnFC1x3g/vFB/wPCS3nNw== X-Received: by 10.194.22.169 with SMTP id e9mr3931023wjf.128.1466195540417; Fri, 17 Jun 2016 13:32:20 -0700 (PDT) MIME-Version: 1.0 References: <2635b3b6-b971-9fb7-5def-26b86eafb54d@fleshgrinder.com> <98f97016-066e-b5a4-8d1d-4bca179315fa@gmx.de> In-Reply-To: Date: Fri, 17 Jun 2016 20:32:10 +0000 X-Gmail-Original-Message-ID: Message-ID: To: Christoph Becker Cc: Alexander Lisachenko , PHP Internals Content-Type: multipart/alternative; boundary=047d7b5d4fc25bab2805357f40d8 Subject: Re: [PHP-DEV] Throwing an Error for require expressions in PHP7.x From: me@kelunik.com (Niklas Keller) --047d7b5d4fc25bab2805357f40d8 Content-Type: text/plain; charset=UTF-8 > > If something is required, one cannot do without it, so there's only one > course of action, namely to bail out. What about gracefully bailing out, like showing that composer dependencies have to be installed? It's just like a method call. Usually you expect a return value, unless there's an exception. > In my opinion, this is the least > surprising way to handle missing required files, especially as it always > has been that way (consider the potential BC break). > As already pointed out, there's no BC break, except for catch 'em all. It's also not surprising, as require + parse error already throws an error instead of stopping with a fatal error. It's surprising that this one still fatals. > Or do you really prefer to be able to do > > try { > require $fileName; > } catch (Error $e) { > echo "Oops, maybe deleted? " . $e; > } > functionDefinedInFileName(); > Yes, I really prefer that. Not that code exactly, but being able to write: try { require $config; } catch (ParseError $e) { } > and get a fatal error that function no() is undefined? I'd rather get a > fatal error that the required file couldn't be opened in the first place. > > If, however, a file is not strictly required, one can (and in my > opinion, should) `include` the file. And yes, there's no absolutely > failsafe way to do this without risking a warning or using the @ > operator, but that affects other filesystem functions (e.g. > file_get_contents() and fopen()) as well. Frankly, I can't see a single > good reason to replace the fatal error with an exception for require, > but leave include etc. alone. And if include would throw an exception, > I don't see the use of changing require at all. > > -- > Christoph M. Becker > --047d7b5d4fc25bab2805357f40d8--