php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65812 Func returns NULL if last stmt is 'Exception' or 'die' inside unreachable else
Submitted: 2013-10-02 12:00 UTC Modified: 2013-10-15 11:54 UTC
From: florian dot mueller at hostpoint dot ch Assigned:
Status: No Feedback Package: CGI/CLI related
PHP Version: 5.5.4 OS: freebsd 9.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: florian dot mueller at hostpoint dot ch
New email:
PHP Version: OS:

 

 [2013-10-02 12:00 UTC] 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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-02 12:20 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2013-10-02 12:20 UTC] 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:30 UTC] mike@php.net
Disable opcache while you're at it.
 [2013-10-02 12:49 UTC] 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-15 11:54 UTC] php-bugs at lists dot php dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC