Forum Moderators: coopster

Message Too Old, No Replies

Variable changes not showing if executed from a function

         

ntbgl

4:27 pm on Jun 23, 2008 (gmt 0)

10+ Year Member



I have a variable that gets edited throughout my php script.

I am able to set the variable and add to it, but a function called that should make addition additions to my variable aren't being represented.

function read(){
$file.="cd";
...
}
$file="ab";
read();
$file.="ef";
echo $file;

My script is running everything inside my custom function, so I know that function is running, however, any data written to $file is not being included.

What I expect "abcdef".
What I get "abef";

Any ideas? Thanks.

cameraman

5:42 pm on Jun 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It should be throwing an error.
You need to declare $file as global [us2.php.net] inside the function.