jordanwb Posted November 28, 2007 Share Posted November 28, 2007 A question about how strings work in PHP. If I pass a string variable into a function does it pass the value or the memory refference? Example: <?php function foo ($input){} $foo = "text"; foo ($foo); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 28, 2007 Share Posted November 28, 2007 Search on Pass by Value and Pass by Reference for PHP. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 I believe it will be the value of that not the refs as you can put direct text input, it will take those comma separated values and apply those as new memory refs for the function's life. <?php $var = "Foo"; function stuff($vardata){ return $vardata; } $var2 = stuff($var); $var3 = stuff("Foo"); var_dump($var2); var_dump($var3); ?> Quote Link to comment Share on other sites More sharing options...
jordanwb Posted November 28, 2007 Author Share Posted November 28, 2007 I have seen something like this: <?php foo (&$foo) { } ?> I've also used that in C++, would pass the ref? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 28, 2007 Share Posted November 28, 2007 I Know what you are talking about because I too have seen it in C the pointers to a mem reference and not the string value, I haven't seen a useful place for it in php, but maybe bridging the gab between php and another language such as C might have its usefulness. Of course the question then becomes how do you find it as it will be random usually Quote Link to comment Share on other sites More sharing options...
jordanwb Posted November 28, 2007 Author Share Posted November 28, 2007 So would placing an amperstand before a variable make it pass the ref ot the value? Quote Link to comment Share on other sites More sharing options...
Orio Posted November 28, 2007 Share Posted November 28, 2007 Yes, you can pass variables by reference. More info in the manual: http://www.php.net/manual/en/functions.arguments.php Orio. Quote Link to comment Share on other sites More sharing options...
jordanwb Posted November 28, 2007 Author Share Posted November 28, 2007 Excellent, Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.