php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34009 PHP 4.4.0 shows on some platforms a return by reference Notice,but it shouldn't
Submitted: 2005-08-05 16:27 UTC Modified: 2005-09-16 21:15 UTC
From: ast at gmx dot ch Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.4.0 OS: Gentoo Linux
Private report: No CVE-ID: None
 [2005-08-05 16:27 UTC] ast at gmx dot ch
Description:
------------
Abstract:
-------------------
PHP 4.4.0 shows a "Notice: Only variable references should be returned by reference in ..." Notice when it shouldn't.
The bug can only be reproduced with PHP 4.4.0. And it can only be reproduced on a few systems, on most it returns the expected result (all test platforms had error_reporting(E_ALL);).
Furthermore, code that seems to be equivalent doesn't result in a Notice. And two different systems with almost the same setup don't show the same results.
I couldn't isolate the bug further than this. Maybe it's a compile options issue, maybe it has to do with the scope of variables, I don't know.

Disclaimer:
-------------------
You may think this is another bogus bug report for the return-by-reference / assign-by-reference / pass-by-reference Notices in PHP 4.4.0.

But I'm quite sure it isn't. I've patched our framework and wrote some recommendations on how to code the right way: http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=32907 . But you don't need to follow this link. I just want to point out that this is a real issue.

Details:
-------------------
Please take a look at the reproduce script.


Reproduce code:
---------------
http://dev.nei.ch/bugs/php440_notice_bug/php440_notice_bug_on_certain_platforms.phps

Expected result:
----------------
Expected result:
----------------
PHP Version is: 4.4.0
no NOTICEs

Actual result:
--------------
Actual result:
--------------
php version is: 4.4.0
Notice: Only variable references should be returned by reference in
php440_notice_bug_on_certain_platforms.php on line 23

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-05 19:50 UTC] ast at gmx dot ch
Here's the reproduce code:

<?php
error_reporting(E_ALL);

if (version_compare(PHPVERSION(), '4.4.0') != 0) print "This reproduce code is only for PHP 4.4.0";

$bar = new Bug();
$baz = $bar->foo();

class Bug {
    var $_flag;
    function Bug() {
	$this->_flag = 0;
    }

    function &foo() {
	if (!$this->_flag) {
	    $false = false;
	    return $false; /* this is line 18 */
	}

	$false = false;
	return $false;
    }
}
?>

Expected result:
----------------
no NOTICEs

Actual result:
--------------
Notice: Only variable references should be returned by reference in
reproduce.php on line 18

I've added the two other methods in the original reproduce code just to show that very slight modifications of the code do not give a PHP Notice.
And please remember that I can't reproduce it on all systems.
 [2005-08-08 10:48 UTC] ast at gmx dot ch
John Lim from the adodb project wrote the following:
> There is nothing wrong with this code.
> 
> I have found this problem normally occurs when php 4.4 is
> being run with an old version of zend optimizer or similar 
> 3rd party software.

Also, one of the ISPs that can reproduce this incorrect behavior said they've compiled PHP statically, but zend was   DSO. They use the same PHP on multiple boxes and only on one they can reproduce this issue. I'll notify them about the statement from John Lim, probably that's it.

If that's the case, the bug is indeed invalid. But it's good to know what can cause this issue.
 [2005-09-16 21:15 UTC] pollita@php.net
The bug here is in Zend Optimizer.  It sees your variable assigned immediately before the return and substitutes the intermediate TMP_VAR for the real variable.

Please report this bug to Zend at http://www.zend.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC