Reply to Re: Variable scope mystery

Your name:

Reply:


Posted by Maarten on 11/18/05 19:18

Thank you for replying, but you are mistaking. This for example works fine,
even when the second function is included from an outside file.

function blah()
{
function blahblah()
{
echo "foo";
}
blahblah();
}
blah();



"daemon" <d43m0n@shaw.ca> wrote in message
news:cxnff.523697$oW2.516262@pd7tw1no...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Maarten wrote:
>> Here is a nice problem. I have two scripts, one calling the other with
>> via
>> an include. The script that is included contains a variable, a function
>> and
>> a call to that function. The variable needs to be accessible to the
>> function, so I declare it having a global scope. Then I execute the
>> function, which should echo the value of the variable. Contrary to what I
>> expected, the variable isn't there.
>>
>> The code of the 2 programs is:
>>
>> script1.php
>> <?php
>> function blah()
>> {
>> include("script2.php");
>> }
>>
>> blah();
>> ?>
>>
>> script2.php
>> <?php
>> $foo = "bar";
>>
>> function blahblah()
>> {
>> global $foo;
>> echo $foo;
>> }
>>
>> blahblah();
>> ?>
>>
>> I can't see anything wrong with the way I set this up, even more since a
>> call to script2.php does exactly what it's suppossed to do: echo the
>> value.
>> What's going on here is beyond me. Anybody has a clue?
>>
>> Kind regards, Maarten
>>
>>
>
> I can... you can't expect to include another function within blah();
>
> To do it, use a class, and include your blahblah(); and just use blah();
> to reference to it within your class::function();
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2 (MingW32)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>
> iD8DBQFDfmZh/WE0aXnOUiYRAmpQAJ4gbRQBepMOTriilvr82GryQuykTQCgk0TZ
> tZ637ZaemoIUKhM4n4Frh2w=
> =f1n2
> -----END PGP SIGNATURE-----

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация