Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not find new created global variables inside a function. #41

Open
sallon88 opened this issue Jun 20, 2013 · 1 comment
Open

can not find new created global variables inside a function. #41

sallon88 opened this issue Jun 20, 2013 · 1 comment

Comments

@sallon88
Copy link

$a = 1;
function test() {
  global $a;
  echo $a;
}
test();

the test() function should print a "1", but under boris, nothing is printed.

@d11wtq
Copy link
Contributor

d11wtq commented Jun 20, 2013

Hmm, yeah, I guess that's confusing. It's expected, since Boris' runloop is running inside a function, which makes it a local variable, not global, unless explicitly declared global.

[1] boris> global $a;
[2] boris> $a = 1;
 → 1
[3] boris> function test() {
[3]     *>   global $a;
[3]     *>   return $a;
[3]     *> }
 → NULL
[4] boris> test();
 → 1
[5] boris>

I could 'fix' it so variables declared within Boris' scope are copied into $GLOBALS, though this could have some unpleasant side-effects too (mostly with GC and cleaning up). I'll have to think about it a bit more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants