$GLOBALS and global $variable; not working in Phalanger?
Posted: March 12th, 2013, 10:12 pm
Hi there,
I'm following some PHP basics tutorial from a book and found some examples about $GLOBALS that do not seem to work in Phalanger.
When I use global $variable; and use it it does not affect the value outside the function. If I try to do the same using $GLOBALS I get a Notice message and again, the value does not get updated.
I'm using the latest release of Phalanger 3 + Phalanger tools for VS 2012.
Here below the code with 3 different examples, 2 taken from PHP documentation web site.
Is the globals functionality supported for Pure CLR phalanger programs?
Thanks in advance.
Carlos
I'm following some PHP basics tutorial from a book and found some examples about $GLOBALS that do not seem to work in Phalanger.
When I use global $variable; and use it it does not affect the value outside the function. If I try to do the same using $GLOBALS I get a Notice message and again, the value does not get updated.
I'm using the latest release of Phalanger 3 + Phalanger tools for VS 2012.
Here below the code with 3 different examples, 2 taken from PHP documentation web site.
- Code: Select all
<?php
class Program
{
static function Main()
{
// Example 1
function updateCounter1()
{
global $counter;
$counter++;
}
function updateCounter2()
{
$GLOBALS["counter"]++;
}
$counter = 10;
//updateCounter2(); // this gives an error : Notice: Undefined offset (counter) in c:\users\carlos\documents
updateCounter1();
echo $counter;
// prints 10 (instead of 11)
// Example 2
function test() {
$foo = "local variable";
echo '$foo in global scope: ' . $GLOBALS["foo"] . "\n";
echo '$foo in current scope: ' . $foo . "\n";
}
$foo = "Example content";
test();
// this gives an error : Notice: Undefined offset (foo) in c:\users\carlos\documents
// and prints:
// $foo in global scope:
// $foo in current scope: local variable
// Example 3
$conf['conf']['foo'] = 'this is foo2';
$conf['conf']['bar'] = 'this is bar';
function foobar() {
global $conf;
var_dump($conf);
}
foobar();
// prints NULL
fgets(STDIN);
return 0;
}
}
?>
Is the globals functionality supported for Pure CLR phalanger programs?
Thanks in advance.
Carlos