FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » array_push() v/s array[$index] = and reference construct &
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
array_push() v/s array[$index] = and reference construct & [message #176701] Wed, 18 January 2012 23:50 Go to next message
cate is currently offline  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 Go to previous message
alvaro.NOSPAMTHANX is currently offline  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
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: an active web design group?
Next Topic: Immediate Requirement for PHP Professionals with 4 to 7 yrs of exp in Hyderabad location
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 17:00:14 GMT 2024

Total time taken to generate the page: 0.02404 seconds