php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25831 overload/__call breaks method Pass by, and return by reference
Submitted: 2003-10-10 19:30 UTC Modified: 2003-12-12 21:02 UTC
Votes:10
Avg. Score:4.5 ± 0.8
Reproduced:10 of 10 (100.0%)
Same Version:0 (0.0%)
Same OS:7 (70.0%)
From: viking at dslnorthwest dot net Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4.3.4RC2-dev OS: all
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: viking at dslnorthwest dot net
New email:
PHP Version: OS:

 

 [2003-10-10 19:30 UTC] viking at dslnorthwest dot net
Description:
------------
When extending the DB_DataObject class using PHP 4.3.3, 
pass-by-reference calls to class methods don't work. 
After removing the call to overload() at the bottom of 
DB_DataObject.php, references work as expected. The 
following comments at the bottom of DB_DataObject 
allude to this:

// technially 4.3.2RC1 was broken!!
// looks like 4.3.3 may have problems too.... 
if ((phpversion() != '4.3.2-RC1') && (version_compare( 
phpversion(), "4.3.1") > 0)) {
   overload('DB_DataObject');
   $GLOBALS['_DB_DATAOBJECT']['OVERLOADED'] = true;     
}

Reproduce code:
---------------
require_once("DB/DataObject.php");

class no_problem
{
	function pass_by_reference(&$ref)
	{
		$ref = "Pass by reference works";
	}
}

class problem extends DB_DataObject
{
	function pass_by_reference(&$ref)
	{
		$ref = "Pass by reference works";
	}
}

$good = &new no_problem();
$bad = &new problem();

$message = "Pass by reference does not work!";
$good->pass_by_reference($message);
print "$message\n";

$message = "Pass by reference does not work!";
$bad->pass_by_reference($message);
print "$message\n";

Expected result:
----------------
Pass by reference works 
Pass by reference works 

Actual result:
--------------
Pass by reference works 
Pass by reference does not work! 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-10 22:12 UTC] alan_k@php.net
simple script to reproduce:

<?

 
class no_problem  {
	function pass_by_reference(&$ref)	{
		$ref = "Pass by reference works";
	}
}



class problem  { 
	function pass_by_reference(&$ref)	{
		$ref = "Pass by reference works";
	}
	// simple dummy call implementation..
    function __call($method,$params,&$return) {
		if ($method == get_class($this)) {
			return true;	
        }
		return false; // not found!
	}
}

overload('problem');


$good = &new no_problem;
$bad = &new problem;

$message = "Pass by reference does not work!";
$good->pass_by_reference($message);
print "$message\n";



$message = "Pass by reference does not work!";
$bad->pass_by_reference($message);
print "$message\n";


?>


should print 
Pass by reference works
Pass by reference works

actually prints
Pass by reference works
Pass by reference does not work!
 [2003-10-27 13:11 UTC] moriyoshi@php.net
The issue was confirmed to have much to do with the current engine's limitation. So then we're trying to make sure that this problem will be fixed in php5.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 00:01:30 2024 UTC