php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49500 call_user_func object parameter is not passed as reference
Submitted: 2009-09-08 15:03 UTC Modified: 2009-09-09 07:40 UTC
From: casper at procurios dot nl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0 OS: Linux
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: casper at procurios dot nl
New email:
PHP Version: OS:

 

 [2009-09-08 15:03 UTC] casper at procurios dot nl
Description:
------------
When call_user_func is called with an object as it's second parameter, 
it's not passed as reference. Instead the PHP warning 'Parameter 1 to 
myFunction() expected to be a reference, value given' is cast.

myFunction() is not called at all.

This is a major compatibility break from 5.2.

Reproduce code:
---------------
class MyClass {
	var $someVar = 'test';
}

function myFunction(&$Object) {
	echo $Object->someVar . "\n";
}

$Object = new MyClass();
myFunction($Object);
call_user_func('myFunction', $Object);


Expected result:
----------------
test
test

Actual result:
--------------
test
PHP warning Parameter 1 to myFunction() expected to be a reference, 
value given

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-08 15:28 UTC] casper at procurios dot nl
My workaround code has a similar issue:

function workaroundforbug49500_call_user_func()
{
	$params = func_get_args();
	$func = array_shift($params);
	return call_user_func_array($func, $params);
}

Casts: 'PHP warning Parameter 1 to myFunction() expected to be a 
reference, value given' too. 

func_get_args() seems affected too.
 [2009-09-08 17:33 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 [2009-09-09 07:40 UTC] casper at procurios dot nl
Jani, could you tell me what bug number this is related to? I have been 
searching for it before I posted this one, searched again now. I found 
duplicate bug #44626 but that one is marked bogus as well.

Two other bugs #43568 & #47402 deal with call_user_func too, but seem 
unrelated.
 [2010-05-08 15:31 UTC] schindler dot andor at pokhalo dot hu
Still bogus in PHP 5.3.2, and it's platform irrelevant. I tested on
Windows and Mac OS X too.

<?php

error_reporting(E_ALL | E_STRICT);

function foo(&$bar)
{
	echo gettype($bar)."\n";
}

class A {}

$foo = 'foo';
$a = new a();
$b = array();

foo($a);
$foo($a);
call_user_func($a);

foo($b);
$foo($b);
call_user_func($b);


Result (PHP 5.3.0+):
--------------------
object
object

Warning: Parameter 1 to foo() expected to be a reference, value given in
.../proba.php on line 18
array
array

Warning: Parameter 1 to foo() expected to be a reference, value given in
.../proba.php on line 22

Expected result (PHP 5.2.x):
----------------------------
object
object
object
array
array
array
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 20:01:31 2025 UTC