473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting 'by reference' error using array_walk. How do I use it then?

I have the following function:

function clean_form( &$from_check ) {
if(is_array($from_check)){
array_walk(&$from_check,'clean_form');
return;
} else {
$value = str_replace(array("\r","\n","Content-Type:"),"",$from_check);
}

When I call this function I get the following warning:

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 array_walk(). 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 the PHP doc it shows referencing the array argument "by reference"; i.e.
'&' , but the runtime says this is a "no go". Then how am I supposed to use
array_walk?

TIA,

Larry Woods
Nov 22 '05 #1
2 2163
lwoods wrote:
function clean_form( &$from_check ) {
array_walk(&$from_check,'clean_form');


You need to define at least two parameters for the function you call with
array_walk: array and item. So try: function clean_form(&$from_check,
$value) { etc. }. That might take care of the error.

--
E. Dronkert
Nov 22 '05 #2
lwoods wrote:
I have the following function:

function clean_form( &$from_check ) {
if(is_array($from_check)){
array_walk(&$from_check,'clean_form');
return;
} else {
$value = str_replace(array("\r","\n","Content-Type:"),"",$from_check);
}

When I call this function I get the following warning:

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 array_walk(). 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 the PHP doc it shows referencing the array argument "by reference"; i.e.
'&' , but the runtime says this is a "no go". Then how am I supposed to use
array_walk?

TIA,


array_walk() is declared to take a reference as the first argument, so
you don't need to use & when you call the function. Just do
array_walk($from_check,'clean_form').

The error message is bogus though. The array will still be passed by
reference in this instance. Report it as a bug.

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
<?php class Grad { var $dbFormExemptionArray = array(); function Grad ($id = '') { ...
2
by: Reply-Via-Newsgroup | last post by:
Folks, I have a multi-dimensional array that I read from my mysql database. I'd like to run strip slashes against each element and I'm pretty sure that array_walk() (or array_map) is likely to...
6
by: steve | last post by:
Hi, I have never used array_walk, and quite frankly, cannot see why I should use it instead of foreach. Can someone shed some light on the cases where array_walk is the one to use, and what php...
2
by: David | last post by:
Hi, Could PHP be used to take a txt file (or set of txt files) and add a string of characters every X number of words or characters? Say a txt file with 50,000 characters/5,000 words how would...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.