array_push() v/s array[$index] = and reference construct & [message #176701] |
Wed, 18 January 2012 23:50 |
cate
Messages: 12 Registered: January 2012
Karma: 0
|
Junior Member |
|
|
I am using a mysql IN clause and building a array of references for
call_user_func_array().
In my XP env (xp, apache, php 5.3.8) this will work:
array_push($param_array, &$include_unique[$i]);
On a linux box, apache, php 5.3.6, it does not. Says " Call-time pass-
by-reference has been deprecated"
But this is allowed...
$param_array[$i] = &$include_unique[$i];
Is there a way to use a push with a reference construct?
Thank you.
|
|
|
Re: array_push() v/s array[$index] = and reference construct & [message #176702 is a reply to message #176701] |
Thu, 19 January 2012 08:50 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
El 19/01/2012 0:50, cate escribió/wrote:
> I am using a mysql IN clause and building a array of references for
> call_user_func_array().
>
> In my XP env (xp, apache, php 5.3.8) this will work:
>
> array_push($param_array,&$include_unique[$i]);
I guess you need to enable error reporting in your Windows set-up.
> On a linux box, apache, php 5.3.6, it does not. Says " Call-time pass-
> by-reference has been deprecated"
>
> But this is allowed...
>
> $param_array[$i] =&$include_unique[$i];
Certainly, since it isn't a function call.
> Is there a way to use a push with a reference construct?
The key point about "Call-time pass-by-reference" is that, when you want
to pass a parameter as reference, it needs to be defined as such within
the function; you cannot decide it at run time. E.g.:
function f($param){
}
$foo = 33;
f(&$foo);
.... triggers:
«Deprecated: Call-time pass-by-reference has been deprecated; If you
would like to pass it by reference, modify the declaration of f(). If
you would like to enable call-time pass-by-reference, you can set
allow_call_time_pass_reference to true in your INI file»
However, this works as expected no matter your settings:
function f(&$param){
}
$foo = 33;
f($foo);
Unluckily, array_push() is a core PHP function written in C, not some
PHP code you can modify. So your options are:
1. Enable allow_call_time_pass_reference
2. Write your own function to implement this behaviour
Of course, array_push() is only useful when you need to append more than
one item at a time.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|