Jump to content


Photo

Trouble with Call-time pass-by-reference


  • Please log in to reply
2 replies to this topic

#1 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 06 July 2006 - 06:25 PM

I'm wanting to pass an array by reference to a function. But I get a warning.

Here is the warning:
[06-Jul-2006 11:13:30] PHP Warning:  Call-time pass-by-reference has been deprecated - argument passed by value;  
If you would like to pass it by reference, modify the declaration of copy_array().  
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, future versions may not support this any longer.  in C:\FTB\dptr1988.mooo.com\htdocs\walk.php on line 137

Here is the function declaration:
<?php
function copy_array($source, &$dest)
{

 foreach($source as $key => $value)
 {
  $dest[$key] = $value;
 }

}
?>

Here is how I call the function:
<?php
copy_array($newstats, &$stats);
?>

I've read the manual and my code seems correct but I still get that warning. Is my function definition wrong?

Thanks
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 06 July 2006 - 07:31 PM

Call like this, withoutthe "&"

copy_array($newstats, $stats);

However, you might find it simpler to

$stats = $newstats;

to copy the array
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 06 July 2006 - 08:52 PM

Thank you barand. It works now.

The reason I made the copy_array() function is that $newstats only contains some of the items that $stats contains. So it's just updating some of the items in $stats rather than copying the whole array

Thanks again
Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users