Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94101 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15879 invoked from network); 18 Jun 2016 01:08:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jun 2016 01:08:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@daveyshafik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@daveyshafik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain daveyshafik.com from 209.85.220.169 cause and error) X-PHP-List-Original-Sender: me@daveyshafik.com X-Host-Fingerprint: 209.85.220.169 mail-qk0-f169.google.com Received: from [209.85.220.169] ([209.85.220.169:35901] helo=mail-qk0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/10-18862-81F94675 for ; Fri, 17 Jun 2016 21:08:40 -0400 Received: by mail-qk0-f169.google.com with SMTP id p10so103000781qke.3 for ; Fri, 17 Jun 2016 18:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daveyshafik-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=CwLw3q3oPeHaElPLmGcY+at6/wk9wNZ1vjdpdKVySCY=; b=ZGQtk6I1444NJvyeMK3dey73jYyPI7k1F0skMa2g86XwkDuJNLninkuxXB9fHv8SUM XvsZc48EJI0Tv/uG2q21MvxM+lTE/P2UxXa61VZm+GVyMU3Zsglt77/1ltz6O7PZ0zbj AO+TulDK03vfr1iyGunZ7+WLtXoBKo3JrRZiYaps3lVrUcZedtcFOc+rwyQmNh+1VSar T9/BFrpqeUPllKwtkRUSKPo88P/zInMLVeEgvB9IELmSYamq8EYcjOWLw4jyrfNPu/Aq 0X3xaP8tBic2CNbkrHsizhOdoTdb+nrp5zNHJxbua9zaWAFlBX2kpoHK5XKWZ5sceTtb 6qaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=CwLw3q3oPeHaElPLmGcY+at6/wk9wNZ1vjdpdKVySCY=; b=iMV34W3VkXEwrTLA32lPN2YfpAE4c9v0fwXVILQYFXdtsNqyxNNa830olVFOo5T/vd Qm9Z+/eeShSLmfTrvnqXsy8AYGVkVgRr2VnhHO30O2Z1ktlkcWVO7LnEp7wECAt9+k1T ckTvRXDlTQVetQjZmmda5WKWKXNIlfbGlyj+E+QUToIIXCBuwoH30AEHk+jyutmkiLty nbkUAqX54R3UR+JC4YeGmvmC7SwCYYGQWQ0VSO5yPBLVo0DzWGL6F0vfy6Al/VDo4OWH nkGDJJdLkV25fxfs9KLH99VIrOrJprAo1BEra928OEjHgpSp39AC2fnRrOMX2VWgX7vt 7oFQ== X-Gm-Message-State: ALyK8tIfx+oo9RBBwSxCQhBSWiahc8+gtvek/QX+TIoBeeRmyC+1dVyJdy062a7oxVxcurliMnyT6oD/+W4gVUux X-Received: by 10.200.38.244 with SMTP id 49mr6226229qtp.32.1466212117070; Fri, 17 Jun 2016 18:08:37 -0700 (PDT) MIME-Version: 1.0 Sender: me@daveyshafik.com Received: by 10.237.54.225 with HTTP; Fri, 17 Jun 2016 18:08:36 -0700 (PDT) In-Reply-To: References: <2635b3b6-b971-9fb7-5def-26b86eafb54d@fleshgrinder.com> <98f97016-066e-b5a4-8d1d-4bca179315fa@gmx.de> Date: Fri, 17 Jun 2016 18:08:36 -0700 X-Google-Sender-Auth: PZPSSPB9on6T3aCApxAhYU2hvLc Message-ID: To: Niklas Keller Cc: Christoph Becker , Alexander Lisachenko , PHP Internals Content-Type: multipart/alternative; boundary=001a114064ee67792f0535831c6f Subject: Re: [PHP-DEV] Throwing an Error for require expressions in PHP7.x From: davey@php.net (Davey Shafik) --001a114064ee67792f0535831c6f Content-Type: text/plain; charset=UTF-8 I'm +1 for this on require. I'd love to see exceptions for all file I/O stuff (no more @fopen()!) but in all likelihood, we'd need a new API for that to keep BC. On Fri, Jun 17, 2016 at 1:32 PM, Niklas Keller wrote: > > > > 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 > > > --001a114064ee67792f0535831c6f--