CallStatic(), call_user_func_array(), references, and PHP 5.3.1?

This is a fun one. TestClass::testFunction(&$string); This works, but it also throws a call-time-pass-by-reference warning. The main issue is that __callStatic's second argument comes in by value.It's creating a copy of the data, unless that data is already a reference.

We can duplicate the calling error thusly: call_user_func_array('testFunction', array( $string )); // PHP Warning: Parameter 1 to testFunction() expected to be a reference, value given call_user_func_array('testFunction', array( &$string )); echo $string; // 'helloworld' I tried to modify the __callStatic method to copy the array deeply by reference, but that didn't work either. I'm pretty sure that the immediate copy caused by __callStatic is going to be a killer here, and that you won't be able to do this without enough hoop jumping to make it a bit sticker, syntax-wise.

Thanks Charles; Yea, I figured that the call magic would be the problem. I've noticed it's popped up in the PHP bugfix requests, yet has not been patched (from what I've found at least) Explicitly passing the arguments by reference of course throws a warning as you've noted, and unfortunately that wouldn't be satisfactory solution anyways. What sort of hoop jumping did you have in mind, no matter how insane?

– Bracketworks Apr 9 at 4:09 Unfortunately the only thing I can come up with would be not using __callStatic at all, which probably isn't going to help you much here. Can you tell us more about what you're trying to accomplish? – Charles Apr 9 at 5:20 Well, it's become an academic trial now, but the purpose initially comes from this question I posted earlier; stackoverflow.Com/questions/5600883/… The first proposed option to handle autoloading unclassed function libraries takes advantage of __callStatic.

Though it may be beneficial for optimization purposes to go a different route, I'd still like to solve this, as it (to me at least) seems like a very clean solution. – Bracketworks Apr 9 at 5:34 1 Hm, interesting idea, though I'm not sure if PHP is the right language to pull off that kind of magic. If this was Perl or Ruby, I'm sure it could be done... – Charles Apr 9 at 5:44 Yea, I was also hoping I could take advantage of this functionality for other purposes.

The autoloading classless function libraries was a start, but I was rolling around some other ideas for a lightweight educational MVC framework I'm developing, and this would have been an asset. I'll keep hunting. Thanks again Charles, if any other ideas come to mind, I'd be happy to hear them.

– Bracketworks Apr 9 at 6:02.

Wow, after more than hour of blowing my mind, I'm still not sure but... mixed call_user_func_array ( callback $function , array $param_arr ) If we use simple logic (in this situation) when class calls function call_user_func_array() it uses static strings as parameters (passed by magic method __callStatic()), so parameter 2 is a string in eyes of call_user_func_array() function and that parameter is also parameter 1 for function testFunction(). It's simply string not a pointer to variable, and that probably is a reason for message like: Warning: Parameter 1 to testFunction() expected to be a reference, value given in ... on line ... In other words, it just can't assign value back to variable that doesn't exist but still, testFunction() expects parameter to be a reference and throws warning because it's not. You can test it out of class like: function testFunction(&$arg){ $arg .

= 'world'; } $string = 'hello'; call_user_func_array('testFunction', array($string)); echo $string; It throws same Warning! So problem is not with class, problem is this function. This function obviously passes function parameters as static data without pointing to variables and functions it calls just can not handle referenced arguments.

Thanks Wh1T3h4Ck5; We've sifted it down to being an issue of calling magic. __call()/__callStatic() don't carry a reference into their defined bodies via the argument array, at least not by any conventional means. The function definition for the call magic (or any magic function as per docs) furthermore does not permit passing the arguments by reference.

– Bracketworks Apr 9 at 4:50.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions