Code Comments
Programming Forum and web based access to our favorite programming groups.Hello,
given the following scenario, how can I make _a visible in 3.php? Below is
what I /tought/ would work...
1.php:
global $_a;
$_a = 42;
2.php:
include('1.php');
include('3.php');
foo();
3.php:
function foo() {
print $_a; //prints nothing
}
TIA,
Mitja
Post Follow-up to this messageMitja said the following on 01/06/2005 00:45:
> Hello,
>
> given the following scenario, how can I make _a visible in 3.php? Below
> is what I /tought/ would work...
>
> 1.php:
> global $_a;
> $_a = 42;
>
> 2.php:
> include('1.php');
> include('3.php');
> foo();
>
> 3.php:
> function foo() {
> print $_a; //prints nothing
> }
>
Declaring a variable as global outside of any function (as you've done)
does nothing.
Move the "global $_a" declaration into the foo() function.
--
Oli
Post Follow-up to this messageOn Wed, 01 Jun 2005 15:25:27 +0200, Oli Filth <catch@olifilth.co.uk> wrote: > Mitja said the following on 01/06/2005 00:45: > > Declaring a variable as global outside of any function (as you've done) > does nothing. > > Move the "global $_a" declaration into the foo() function. > Fancy seeing you here... :) Thanks a bunch, works just the way it should. Mitja
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.