Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #12901

Re: weird global issue

From The Natural Philosopher <tnp@invalid.invalid>
Newsgroups comp.lang.php
Subject Re: weird global issue
Date 2014-02-23 20:41 +0000
Organization albasani.net
Message-ID <ledmed$ps4$1@news.albasani.net> (permalink)
References <ledeug$a34$1@news.albasani.net> <0.2fc68c45e0c0e5aba897.20140223191649GMT.87k3cltza6.fsf@bsb.me.uk>

Show all headers | View raw


On 23/02/14 19:16, Ben Bacarisse wrote:
> The Natural Philosopher <tnp@invalid.invalid> writes:
>
>> Consider
>> <?php
>> $x=array();
>>
>> function foo()
>> {
>> global $x;
>> foreach($x as $p) // fails with invalid type
>> 	{
>> 	}
>> }
>> ?>
>
> foo isn't called in this example, so what you've posted is not the
> actual code that's failing.  The code will fail if the call to foo comes
> too early, specifically before the assignment happens, but maybe you can
> post a full example that fails?
>

the call to foo is after the variable is initialised.

I tested it by echoing gettype($x); both after initialising and inside 
the function

It was fine outside the function  and then returned NULL inside it.

I suspect the problem is in the way I am, 'eval' ing the code.

Provably the eval interpreter doesnt quite handle scope in the same way 
that PHP itself does. And adding a global $x 'passes it up' to the 
calling program.




> <snip>
>


-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

weird global issue The Natural Philosopher <tnp@invalid.invalid> - 2014-02-23 18:33 +0000
  Re: weird global issue richard <noreply@example.com> - 2014-02-23 13:40 -0500
  Re: weird global issue Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-23 19:59 +0100
    Re: weird global issue The Natural Philosopher <tnp@invalid.invalid> - 2014-02-23 20:35 +0000
      Re: weird global issue Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-23 16:37 -0500
      Re: weird global issue Arno Welzel <usenet@arnowelzel.de> - 2014-03-19 16:26 +0100
        Re: weird global issue The Natural Philosopher <tnp@invalid.invalid> - 2014-03-19 17:16 +0000
          Re: weird global issue Scott Johnson <noonehome@chalupasworld.com> - 2014-03-19 14:21 -0700
  Re: weird global issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-23 19:16 +0000
    Re: weird global issue The Natural Philosopher <tnp@invalid.invalid> - 2014-02-23 20:41 +0000
      Re: weird global issue Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-23 21:49 +0100
      Re: weird global issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-02-23 20:59 +0000
    Re: weird global issue Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-23 16:38 -0500
  Re: weird global issue Mladen Gogala <gogala.mladen@gmail.com> - 2014-02-23 22:09 +0000

csiph-web