Edit report at https://bugs.php.net/bug.php?id=65812&edit=1
ID: 65812
Comment by: florian dot mueller at hostpoint dot ch
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
Type: Bug
Package: CGI/CLI related
Operating System: freebsd 9.2
PHP Version: 5.5.4
Block user comment: N
Private report: N
New Comment:
Yes, I'm sorry I reported this.
This has to do with opcache and is no php bug.
Thanks for the quick reply!
Previous Comments:
------------------------------------------------------------------------
[2013-10-02 12:30:31] m...@php.net
Disable opcache while you're at it.
------------------------------------------------------------------------
[2013-10-02 12:20:17] ni...@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
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant