Hi all, On Sun, May 17, 2015 at 8:44 AM, Levi Morrison <le...@php.net> wrote:
> On Sat, May 16, 2015 at 2:17 PM, Rowan Collins <rowan.coll...@gmail.com> > wrote: > > On 16/05/2015 20:15, Levi Morrison wrote: > >> > >> The difference is that as time goes on and I've written code for PHP 7 > >> I was hit by this issue. It's an even bigger issue than even I > >> realized during voting. How many people who voted on that issue have > >> played with the code from both scenarios? Few, I can't guarantee it > >> but given the historical precedent it's almost certainly true. > > > > > > Can you give an example of the issue you were hit with? A sample program > / > > scenario, where failure to catch an EngineException caused behaviour that > > was in some way worse than that under PHP 5? > > Here's a simplified example that illustrates one issue: > > <?php > > set_error_handler(function(){ > echo "Handled."; > }); > > function foo(callable $f) {} > > try { > foo("bar is not callable"); > } catch (Exception $e) { > echo "Caught."; > } > > echo "Done.", PHP_EOL; > > ?> > > In PHP 5 this prints "Handled.Done". Under PHP 7 this fails with: > > > Fatal error: Argument 1 passed to foo() must be callable, string given > > Note that if the TypeException had been caught by catch (Exception $e) > the program would have still been correct. This kind of setup exists > in PHPUnit for example; even if the test has some bad syntax or > failure the testing harness needs to continue. There are other valid > uses as well. > > The only way to make this work in both PHP 5 and 7 is to modify the > code, despite the program being 100% correct under PHP 5 and the > documented semantics. We should consider internal function error/exception also. New ZPP raises type error. <?php mt_srand('999999999999999999999999999'); mt_rand(0, 100); ?> produces E_WARNING Warning: mt_srand() expects parameter 1 to be integer, string given in - on line 2 If we are going to break codes, it is better to break code consistently. Is it possible treat each line enclosed by try {}? e.g. <?php try { mt_srand('999999999999999999999999999'); } catch (WhateverException $e) { // do something useful } try { mt_rand(0, 100); } catch (WhatEverException $e) { // do something useful } ?> rather than <?php try { mt_srand('999999999999999999999999999'); mt_rand(0, 100); } catch (WhateverException $e) { // do something useful } ?> For example, set_exception_handler(callback $callback [, bool $single_line_try_block = FALSE]) Regards, -- Yasuo Ohgaki yohg...@ohgaki.net