Jump to content

Recommended Posts

Hi Guys

 

Probably a simple answer to this.

 

Writing a script where I have a foreach to escape data in a multi dimensionsal array - destined for the database.

 

I want to preserve the the escaped values in the array so I've passed in the value by referece. See code below:

 

foreach($myarray as $key=>$value){

foreach($value as $k=>$v){

$v =   $mysqli->real_escape_string(&$v);
echo  $v ."<br/>";

}
  
  }

 

 

I've switched on error_reporting(E_STRICT), because i read it was good practice to build your scripts with this on.

 

Anyway - when i pass by reference I get a message as follows:

 

Deprecated: Call-time pass-by-reference has been deprecated in C:\wamp\www\wh\C.php on line 105

 

So if pass by reference is deprecated, what's the alternative?

 

I realise i could pass the new values to a new array. But does this mean i shouldn't pass by reference anymore?

 

Many thanks and sorry for going round the planet to ask such a simple question.

 

Drongo

 

 

Link to comment
https://forums.phpfreaks.com/topic/259148-pass-by-reference-deprecated/
Share on other sites

The property way to use a parameter as a reference is to declare that in the function, then just pass the variable as normal.  Example:

 


function myFunc(&$ref){
    $ref = 567;
}


$v = 123;
myFunc($v);

 

 

You should only be using the reference if you need too.  Your pasted code doesn't look like anything that would need to use a reference so just remove it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.