Bug #73217 [Opn->Nab]: Finally block not executed
| From: | nikic@php.net | Date: | Sat, 01 Oct 2016 16:47:41 +0000 |
| Subject: | Bug #73217 [Opn->Nab]: Finally block not executed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204391@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73217&edit=1
ID: 73217
Updated by: nikic@php.net
Reported by: thekid@php.net
Summary: Finally block not executed
-Status: Open
+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:
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.)
Previous Comments:
------------------------------------------------------------------------
[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