Bug #65812 [Fbk->NoF]: Func returns NULL if last stmt is 'Exception' or 'die' inside unreachable else

From: Date: Tue, 15 Oct 2013 11:54:53 +0000
Subject: Bug #65812 [Fbk->NoF]: Func returns NULL if last stmt is 'Exception' or 'die' inside unreachable else
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182275@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65812&edit=1 ID: 65812 Updated by: php-bugs@lists.php.net Reported by: florian dot mueller at hostpoint dot ch Summary: Func returns NULL if last stmt is 'Exception' or 'die' inside unreachable else -Status: Feedback +Status: No Feedback Type: Bug Package: CGI/CLI related Operating System: freebsd 9.2 PHP Version: 5.5.4 Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2013-10-02 12:49:01] florian dot mueller at hostpoint dot ch Yes, I'm sorry I reported this. This has to do with opcache and is no php bug. Thanks for the quick reply! ------------------------------------------------------------------------ [2013-10-02 12:30:31] mike@php.net Disable opcache while you're at it. ------------------------------------------------------------------------ [2013-10-02 12:20:17] nikic@php.net I can't reproduce this on Ubuntu, so this is either FreeBSD specific or has something to do with your environment. Could you try running your script with php-cgi -n and see if the problem persists? ------------------------------------------------------------------------ [2013-10-02 12:00:03] florian dot mueller at hostpoint dot ch Description: ------------ Important: The problem occurs only with php-cgi binary and not with php binary. The problem is, that the following snipped returns NULL instead of true. My guess is, that it has to do with a) if($variable) and b) the fact that "throw new Exception" is the last expression before return. function testMinimal(){ $foo = true; if($foo){ echo ''; } else { throw new Exception('foo'); } return true; } A attached a test script with several cases. For example this one returns NULL as well: function testMinimalDie(){ $foo = true; if($foo){ echo ''; } else { die(); } return true; } whereas those two work: function testMinimalNoVar(){ if(true){ echo ''; } else { throw new Exception('foo'); } return true; } function testMinimalHack(){ $foo = true; if($foo){ echo ''; } else { throw new Exception('foo'); } $someUnrelatedVariable=1; return true; } Test script: --------------- <?php echo "testMinimal "; var_dump(testMinimal()); echo "testMinimalOk "; var_dump(testMinimalOk()); echo "testMinimalNoEx "; var_dump(testMinimalNoEx()); echo "testMinimalDie "; var_dump(testMinimalDie()); echo "testMinimalDivZero "; var_dump(testMinimalDivZero()); echo "testMinimalNoVar "; var_dump(testMinimalNoVar()); echo "testMinimalEEE "; var_dump(testMinimalEEE()); echo "testMinimalEE "; var_dump(testMinimalEE()); echo "testMinimalReturnFalse "; var_dump(testMinimalReturnFalse()); echo "testMinimalHack "; var_dump(testMinimalHack()); function testMinimal(){ $foo = true; if($foo){ echo ''; } else { throw new Exception('foo'); } return true; } function testMinimalHack(){ $foo = true; if($foo){ echo ''; } else { throw new Exception('foo'); } $someUnrelatedVariable=1; return true; } function testMinimalEEE(){ $foo = true; if($foo===true){ echo ''; } else { throw new Exception('foo'); } return true; } function testMinimalEE(){ $foo = true; if($foo==true){ echo ''; } else { throw new Exception('foo'); } return true; } function testMinimalNoVar(){ if(true){ echo ''; } else { throw new Exception('foo'); } return true; } function testMinimalReturnFalse(){ if(true){ echo ''; } else { return false; } return true; } function testMinimalNoEx(){ $foo = true; if($foo){ echo ''; } else { echo 'gugus'; } return true; } function testMinimalDie(){ $foo = true; if($foo){ echo ''; } else { die(); } return true; } function testMinimalDivZero(){ $foo = true; if($foo){ echo ''; } else { 0/0; } return true; } function testMinimalOk(){ $foo = true; if($foo){ echo ''; } return true; } ?> Expected result: ---------------- testMinimal bool(true) testMinimalOk bool(true) testMinimalNoEx bool(true) testMinimalDie bool(true) testMinimalDivZero bool(true) testMinimalNoVar bool(true) testMinimalEEE bool(true) testMinimalEE bool(true) testMinimalReturnFalse bool(true) testMinimalHack bool(true) Actual result: -------------- testMinimal NULL testMinimalOk bool(true) testMinimalNoEx bool(true) testMinimalDie NULL testMinimalDivZero bool(true) testMinimalNoVar bool(true) testMinimalEEE NULL testMinimalEE NULL testMinimalReturnFalse bool(true) testMinimalHack bool(true) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65812&edit=1

« previous php.bugs (#182275) next »