Bug #73217 [Com]: Finally block not executed
Edit report at https://bugs.php.net/bug.php?id=73217&edit=1
ID: 73217
Comment by: thekid@php.net
Reported by: thekid@php.net
Summary: Finally block not executed
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Windows
PHP Version: 7.1.0RC3
Block user comment: N
Private report: N
New Comment:
OK, I understand. This is originally a part of a unittest verifying the finally block
is run; which it still is, just cannot change the return value anymore. Will need to rewrite it
then.
Previous Comments:
------------------------------------------------------------------------
[2016-10-01 16:47:40] nikic@php.net
The new behavior is correct. "return $r" is what determines the return value, and it is
not relevant if $r is modified afterwards. Due to a bug this was not enforced previously in certain
cases.
(This applies also to by-reference returns in that the returned reference is fixed. This means that
the value of the returned reference may still be changed, but it's not possible to reassign the
reference itself.)
------------------------------------------------------------------------
[2016-10-01 16:33:35] thekid@php.net
Description:
------------
There is a behavior change from PHP 7.0 -> PHP 7.1 with how finally blocks get executed
Test script:
---------------
<?php
function test() {
$r= [];
try {
$r[]= 'Try';
throw new Exception('Error');
} catch (Exception $e) {
$r[]= 'Catch';
return $r;
} finally {
$r[]= 'Finally';
}
}
var_dump(test());
Expected result:
----------------
array(3) {
[0]=>
string(3) "Try"
[1]=>
string(5) "Catch"
[2]=>
string(7) "Finally"
}
Actual result:
--------------
array(2) {
[0]=>
string(3) "Try"
[1]=>
string(5) "Catch"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73217&edit=1
Thread (4 messages)