Bug #73217 [Nab]: Finally block not executed

From: Date: Mon, 03 Oct 2016 10:14:35 +0000
Subject: Bug #73217 [Nab]: Finally block not executed
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204421@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:         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:

See https://bugs.php.net/bug.php?id=72215


Previous Comments:
------------------------------------------------------------------------
[2016-10-02 09:03:20] thekid@php.net

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.

------------------------------------------------------------------------
[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)

« previous php.bugs (#204421) next »