Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94067 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22925 invoked from network); 17 Jun 2016 08:29:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2016 08:29:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=lisachenko.it@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=lisachenko.it@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.46 as permitted sender) X-PHP-List-Original-Sender: lisachenko.it@gmail.com X-Host-Fingerprint: 209.85.215.46 mail-lf0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:35062] helo=mail-lf0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/40-18862-6D4B3675 for ; Fri, 17 Jun 2016 04:29:10 -0400 Received: by mail-lf0-f46.google.com with SMTP id l188so53297978lfe.2 for ; Fri, 17 Jun 2016 01:29:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=/Wq3Yiui9/ZvfEE3aDCfe6MeL174/iRwd5+Yo4CFRQs=; b=o4EWDSu6lCq8kWilnVnseMivlmlE87lylVmL+PZyU0RyNIb6wZd3DnJmvVn+Sg9dzI GZtxipj10lU8g0ZORC4EOaDDvzq3Cew75i7Zn83zW7BlK1PWzZsleskYM8fCNBHCL5uU bXCf5uc23ab1b99ogpt+7FzLubnYNrTHvGBjq4KVO6/cCgdNRbE7HGJqq5Y22THVgOfh knfw/GBE1IUyHmnprk3zdA6lklxg4yWJR73hajYhsKW5phf3DPgUGduIBGXYcTyrcNnJ bWw+LdslUp4O2nSKr3BxeR1YIg1fxtU9d2cZOc7dOWJDSOBWo9VxAWEcXN+ouvrWjtI1 2fwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=/Wq3Yiui9/ZvfEE3aDCfe6MeL174/iRwd5+Yo4CFRQs=; b=gGuox2j8Zpbke0GBOkt60Dc9HUTB0Yf5t5zpQTrwSYK+cVWKeD8QQLgx5gtF6aDQTl XI2/o28xSj/QjLYzktk1fwixBAIYmgn5MMtdCBOov8SAfCpOiNpdI4CgKihhUqBxH2aS 9+3MY2oGUTw/c/gvHOfwMgIH+Ewzn4gJdEKNqk+8j0k2kq4bxytPn1VvkNT+Rv+LuQCK VkzJtDuvXoQXGKalukk7xw8PiJu1uI0njbpYn1Mq7dxJIByq5365ASJCgdaL46YCv+c1 TdjRXfnK+47Ys0DCnn9pY9gZmS3WvZZV+CbcZddPu+I6hCglDKxjLzNZzOqnNWJF/S9l FHeA== X-Gm-Message-State: ALyK8tJB++tS55Lz/8F1e7wpsMImqbFJrwXp89WZ5XcDLkCtiss9wOzy4rErTgLg8X5xsh37kKnKriVd+zhx6Q== X-Received: by 10.25.208.144 with SMTP id h138mr245143lfg.128.1466152147355; Fri, 17 Jun 2016 01:29:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.136.6 with HTTP; Fri, 17 Jun 2016 01:29:06 -0700 (PDT) In-Reply-To: References: <2635b3b6-b971-9fb7-5def-26b86eafb54d@fleshgrinder.com> Date: Fri, 17 Jun 2016 11:29:06 +0300 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=001a114000d0ee0d520535752597 Subject: Re: [PHP-DEV] Throwing an Error for require expressions in PHP7.x From: lisachenko.it@gmail.com (Alexander Lisachenko) --001a114000d0ee0d520535752597 Content-Type: text/plain; charset=UTF-8 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: if (file_exists($fileName) && is_readable($fileName)) { @include $fileName; // Silencing errors for the case of race-condition, etc } Pay an attention, that we always need to put the silencing operator here to prevent warnings, etc. This also hides all internal errors for parsing, thanks to the PHP. And we can't easily detect the reason why include was failed. Only possible way is to register error_handler and throw an instance of ErrorException. But if require will throw an Error, nothing will changed, because unhandled Error will produce a Fatal Error, but all modern code will be able to handle this situation. --001a114000d0ee0d520535752597--