Bug #74569 [NEW]: Return in a finally clause silently ignores an exception thrown in a try clause

From: Date: Wed, 10 May 2017 16:44:51 +0000
Subject: Bug #74569 [NEW]: Return in a finally clause silently ignores an exception thrown in a try clause
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209047@lists.php.net to get a copy of this message
From:             trianman at gmail dot com
Operating system: Any
PHP version:      7.1.4
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Return in a finally clause silently ignores an exception thrown in a try clause

Description:
------------
Return in a finally clause silently ignores an exception thrown in a try
clause.
I understand that there is no way to handle an exception here, but it
MUST NOT be silently dropped out.

The interpreter should trigger an E_NOTICE or something similar here.

Looks like any version of PHP from 5.6 to 7.1.4 behaves in the same
manner: https://3v4l.org/C16rP

Here is a similar issue: https://bugs.php.net/bug.php?id=68270

Test script:
---------------
<?php

class MyException extends Exception
{
    public function __construct($message = "", $code = 0, Throwable
$previous = null)
    {
        print "2. Exception constructor\n";
        parent::__construct($message, $code, $previous);
    }
}

function ololo() {
    try {
        print "1. Start\n";
        throw new MyException("4. Exception message\n");
    } finally {
        return "3. Return statement\n";
    }
}

try {
    print ololo();
} catch (Exception $e) {
    print $e->getMessage();
}

Expected result:
----------------
1. Start
2. Exception constructor
PHP NOTICE: Dropped exception due the return statement in a finally
block
3. Return statement

Actual result:
--------------
1. Start
2. Exception constructor
3. Return statement

-- 
Edit bug report at https://bugs.php.net/bug.php?id=74569&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74569&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74569&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74569&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74569&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74569&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74569&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74569&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74569&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74569&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74569&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74569&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74569&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74569&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74569&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74569&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74569&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74569&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74569&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74569&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74569&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#209047) next »