0

I need to call a dynamic function and send the current object as reference in the said function.

In PHP 5.3 this works, as opposed to PHP 5.4:

$value = call_user_func("MyFunction", $value, $row, $this,etc....); // using $this because this call happends inside an object

Where MyFunction is :

function MyFunction($value,&$row,&$column,&$grid,etc...){
    ...
}// myFunction is a standalone function, not inside any object

In PHP 5.4 I get the error "parameter expected to be a reference, value given". The respective error refers to the $this parameter at the call_user_func line. It seems that if I specify $this directly in the call it is considered as pass-by-value because if I do like this, it works:

$that = &$this;
$value = call_user_func("MyFunction", $value, $row, $that,etc....);

And I have to do this with all the other parameters which are related to the current object.

Question: is there any other - more elegant - way to do this ? Am I missing something?

Catalin
  • 773
  • 1
  • 7
  • 18

1 Answers1

2

You don't need to accept the parameter by reference in the first place. Change your function to:

function MyFunction($value, $row, $column, $grid, ..) ..

Object values are references by nature anyway, passing them by reference doesn't add anything really and/or may not do what you think it does.

deceze
  • 510,633
  • 85
  • 743
  • 889