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); ?> Link to comment https://forums.phpfreaks.com/topic/79176-solved-are-string-variables-passed-by-ref-or-value/ 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. Link to comment https://forums.phpfreaks.com/topic/79176-solved-are-string-variables-passed-by-ref-or-value/#findComment-400800 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); ?> Link to comment https://forums.phpfreaks.com/topic/79176-solved-are-string-variables-passed-by-ref-or-value/#findComment-400803 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? Link to comment https://forums.phpfreaks.com/topic/79176-solved-are-string-variables-passed-by-ref-or-value/#findComment-401123 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 Link to comment https://forums.phpfreaks.com/topic/79176-solved-are-string-variables-passed-by-ref-or-value/#findComment-401164 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? Link to comment https://forums.phpfreaks.com/topic/79176-solved-are-string-variables-passed-by-ref-or-value/#findComment-401194 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. Link to comment https://forums.phpfreaks.com/topic/79176-solved-are-string-variables-passed-by-ref-or-value/#findComment-401202 Share on other sites More sharing options...
jordanwb Posted November 28, 2007 Author Share Posted November 28, 2007 Excellent, Thanks. Link to comment https://forums.phpfreaks.com/topic/79176-solved-are-string-variables-passed-by-ref-or-value/#findComment-401212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.