$GLOBALS and global $variable; not working in Phalanger?
3 posts
• Page 1 of 1
$GLOBALS and global $variable; not working in Phalanger?
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
- carlosqt
- Posts: 7
- Joined: March 10th, 2013, 7:21 pm
Re: $GLOBALS and global $variable; not working in Phalanger?
Hi Carlos,
$GLOBALS magic variable works in the same way as in legacy PHP.
However pure mode is free of global code, and globals cannot be used - because of compatibility with CLR which does not have global variables.
Thanks,
$GLOBALS magic variable works in the same way as in legacy PHP.
However pure mode is free of global code, and globals cannot be used - because of compatibility with CLR which does not have global variables.
Thanks,
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: $GLOBALS and global $variable; not working in Phalanger?
Got it.
Thanks for the info Jakub.
Carlos
Thanks for the info Jakub.
Carlos
- carlosqt
- Posts: 7
- Joined: March 10th, 2013, 7:21 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 6 guests