the declaration of global variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
victor
Forum Commoner
Posts: 65
Joined: Fri Feb 13, 2004 1:36 am

the declaration of global variables

Post by victor »

does anyone knows if I set global register to off in the php.ini will declaring a variable as global in a function still take effect?

<?php
function get($var){
return $var;
}

function set($var, $val){
global $var;
$var = $val;
}
?>

If i use the function in another file say try.php

set($donkey, 5);

echo ($donkey); (does not seems to print out... cos no value :cry: )

any kind soul out there pls help..
victor
Forum Commoner
Posts: 65
Joined: Fri Feb 13, 2004 1:36 am

Post by victor »

btw, should be echo get($donkey).
victor
Forum Commoner
Posts: 65
Joined: Fri Feb 13, 2004 1:36 am

Post by victor »

it is settled, just add global into get function also..

:oops:
Post Reply