TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Call Time by pass by Reference Deprecated??? :S (http://www.talkphp.com/general/2110-call-time-pass-reference-deprecated-s.html)

Orc 01-27-2008 04:19 AM

Call Time by pass by Reference Deprecated??? :S
 
Code:

Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of is_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
I am getting this error at:
PHP Code:

// Try & Catch Exeception
    
try {
  if (
is_array(&$meta))
  {
  
// Combines both $html & $meta with their keys and values
  
array_combine$html, &$meta);
  
  
  
  }
  }
   catch(
Exception $meta) {
    throw new 
Exeception("The Meta variable is not an Array, please change this");
    } 


Village Idiot 01-27-2008 05:15 AM

Why are you passing by reference? Take the & away and pass by value.

Orc 01-27-2008 05:16 AM

Quote:

Originally Posted by Village Idiot (Post 9751)
Why are you passing by reference? Take the & away and pass by value.

I thought '&' ment reference, though I wasn't for sure. Thanks at least, though could you tell me when to pass to reference? ( not classes/objects )

Village Idiot 01-27-2008 05:21 AM

I dont fully understand refferences, I until now thought they where like C++ pointers. Go here for an explaination PHP: References Explained - Manual

Orc 01-27-2008 05:24 AM

Quote:

Originally Posted by Village Idiot (Post 9753)
I dont fully understand refferences, I until now thought they where like C++ pointers. Go here for an explaination PHP: References Explained - Manual

I see you edited your post :P, theres a reference and deference in C++ though, and they are used for the memory address, pointing by, it's a long story really..

Edit: BLAH!!! stop editing :P Well, now that you say that now, keep editing xD

Village Idiot 01-27-2008 05:27 AM

I am officially done editing, I don't fully understand refferences. I will take another crack at it tomorrow when I am not tired. I'm going to bed now.

Orc 01-27-2008 05:28 AM

Quote:

Originally Posted by Village Idiot (Post 9756)
I am officially done editing, I don't fully understand refferences. I will take another crack at it tomorrow when I am not tired. I'm going to bed now.

Ah, when you're ready to explain it, at least explain it here first xD But thanks for helping me! :D

xenon 01-27-2008 09:40 AM

If you need to pass by reference instead of value, use the referencing operator in the function declaration, instead of sending a reference at call time. Like so:

PHP Code:

do_stuff( &$var 

becomes:

PHP Code:

do_stuff$var );

function 
do_stuff( &$var 

References will not create a copy of the variable being sent, but instead use the memory handle of that variable to manipulate it. I don't know if there is actually more to know about them, but the fact that a reference to a variable points to the same variable, where as a copy points to another, different, variable (changing the reference affects the original variable, changing the copy does not).

wGEric 01-28-2008 09:20 PM

Quote:

Originally Posted by xenon (Post 9765)
References will not create a copy of the variable being sent, but instead use the memory handle of that variable to manipulate it. I don't know if there is actually more to know about them, but the fact that a reference to a variable points to the same variable, where as a copy points to another, different, variable (changing the reference affects the original variable, changing the copy does not).

To expand on this, variables are only available within their scope. Scope being within a function, loop, whatever. So when you have a variable you are passing into a function through a parameter, it creates a copy of that variable in memory for use within the function because the function is not within the scope of the variable. So you can do whatever you want with the variable you passed in through a parameter and not have it change the variable outside of the function. When you pass the variable in by reference, it doesn't create the copy and extends the scope of the variable to include the function so changing it within the function changes outside of the function as well.


All times are GMT. The time now is 03:54 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0