Re: Throwing an Error for require expressions in PHP7.x

From: Date: Fri, 17 Jun 2016 15:44:22 +0000
Subject: Re: Throwing an Error for require expressions in PHP7.x
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-94085@lists.php.net to get a copy of this message
2016-06-17 11:46 GMT+02:00 Christoph Becker <cmbecker69@gmx.de>: > 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?

« previous php.internals (#94085) next »