Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94086 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77841 invoked from network); 17 Jun 2016 16:47:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2016 16:47:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.22 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.22 mout.gmx.net Received: from [212.227.17.22] ([212.227.17.22:56187] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/1A-18862-B8924675 for ; Fri, 17 Jun 2016 12:47:08 -0400 Received: from [192.168.2.102] ([217.82.228.97]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0MJWAZ-1bGxzh40PT-0033VU; Fri, 17 Jun 2016 18:47:03 +0200 To: Niklas Keller References: <2635b3b6-b971-9fb7-5def-26b86eafb54d@fleshgrinder.com> <98f97016-066e-b5a4-8d1d-4bca179315fa@gmx.de> Cc: Alexander Lisachenko , PHP Internals Message-ID: Date: Fri, 17 Jun 2016 18:47:22 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:SSzUC45PqD1//BwpjNawwQXjyNVEfWdnpWXCvUmh5fVekHwHkqJ V5NAdfDKZDuWBsLzJS6WvCcYC1aAUlyufQH6OGGkw3tWBZ6NEqWq1VegbzidUybMtb0eTi5 m3gqb8lxhGpLbKsNShnckfVCrcXVfeCMwfYOtVKiib5OPbEeFZctSLPV4HgCYLZsoZ6Iuzj Y5Zk2t+OR5U0YP0hS0m1w== X-UI-Out-Filterresults: notjunk:1;V01:K0:VvPwJA7bkmk=:vhkrE63LaU/fFmxeHvEZg2 rN998OAOq5176W6CxQBcZKCMBJcwjSXOjcz24CkYjPiO/v/ieeeTJp3KrfPPzs7PMOdpgiTH2 XMozfQuf27z5Q2zmdqugTawJq7zvrVzHeKw1Ss0aeE/WXDzdbXVgjXdqZKGXiBiHsldlUAIpn gsTd8It8QjDYzS6wAdkCSA+NfSBy7vvaSDGoQ9jH0IVT1EJ+CK46CNM2hzynH9KJxcNNBRzKl CUsdiL/FkRfl/pfNXziuLzXdGLaHZloH07MkgmuT59J6GLjo6/m650x9thR//tUP45+1XkpL0 pUXmLOluTYW9OZau/hP3nDLnBw5ROeVNFDGuFLEUnjdkTAtgYHURFcNUnzAQAdE2JpJFsXnFL gWp61Y1IYC4puO89tEVcbc1w49n467DS8+A0DM1unJyPDonrweyrAAUP5xM1Po2HB45PogJfX Q00wuKny37M3WjZ1m5MJmQjRSIifhzBrmIGAhbEkQrzE/5WuJ+WbTCy83F1KvZ4VlYipQd+7A DEDol/ETytvLvDmIRicBfa5YNtk7Rv83SqL7YH94kD/hcIh8I8Os0YTCIi4GMNfMHttj/DULM B9XS5Y9kC1O9z60GpQkTHdMxJZsMpBuIVFwvPN6FuxCKh5drCH1P6t3dgUlRCgK0B2Ll4jTyZ uqTDH8s3X6BLKZngrDlNUs5cWxSae1T3UZH0v/0xFheq1+BZQCNwYVGBiEHTZ/zR+uEEL8fVH f0avwDi75OksFyv2kp66OkJEEjBYvOllmyaV5xK9WqUqMTr0FvaVxTklVxTgqAhHwZtuoSz66 V8jtZfn Subject: Re: [PHP-DEV] Throwing an Error for require expressions in PHP7.x From: cmbecker69@gmx.de (Christoph Becker) On 17.06.2016 at 17:44, Niklas Keller wrote: > 2016-06-17 11:46 GMT+02:00 Christoph Becker : > >> On 17.06.2016 at 10:29, Alexander Lisachenko wrote: >> >>> Nikita, Dmitry, ping. What do you think, shouldn't we replace all >> possible >>> places with Fatal Errors with correct throwing of Error exceptions? In >>> this concrete case it's for "require" operator. >>> >>> From what I can see Error will give us more control over the file loading >>> process and make it more atomic, because additional checks >>> if(file_exists($file) && is_readable($file)) generate extra stat >> commands, >>> they are slow and not reliable, because for highload projects, we can be >> in >>> the situation where "if" succeeded, but the "require" will fail because >> our >>> file was deleted immediately after check. >>> >>> Code like this: >>> try { >>> require $fileName; >>> } catch (Error $e) { >>> echo "Oops, maybe deleted? " . $e; >>> } >>> >>> is much more reliable than following, by using "include" instead of >>> "require". This was suggested in https://bugs.php.net/bug.php?id=72089: >> >> I have re-opened this ticket. >> >>> if (file_exists($fileName) && is_readable($fileName)) { >>> @include $fileName; // Silencing errors for the case of >> race-condition, >>> etc >>> } >> >> I'm not generally against throwing exceptions from include (or several >> other filesystem functions, for that matter), but the BC break has to be >> considered. I am, however, still opposed to offer the ability to catch >> a failing *require*. > > Why? If something is required, one cannot do without it, so there's only one course of action, namely to bail out. 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). Or do you really prefer to be able to do try { require $fileName; } catch (Error $e) { echo "Oops, maybe deleted? " . $e; } functionDefinedInFileName(); 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