array_push() v/s array[$index] = and reference construct &

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am using a mysql IN clause and building a array of references for

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 &

El 19/01/2012 0:50, cate escribió/wrote:
Quoted text here. Click to load it

I guess you need to enable error reporting in your Windows set-up.

Quoted text here. Click to load it

Certainly, since it isn't a function call.

Quoted text here. Click to load it

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;

... 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;

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.

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Site Timeline