Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12907
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: weird global issue |
| Date | 2014-02-23 16:37 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <ledpn7$uor$2@dont-email.me> (permalink) |
| References | <ledeug$a34$1@news.albasani.net> <530a450b$0$9514$9b4e6d93@newsspool1.arcor-online.net> <ledm1l$omj$2@news.albasani.net> |
On 2/23/2014 3:35 PM, The Natural Philosopher wrote:
> On 23/02/14 18:59, Christoph Michael Becker wrote:
>> The Natural Philosopher wrote:
>>
>>> Consider
>>> <?php
>>> $x=array();
>>>
>>> function foo()
>>> {
>>> global $x;
>>> foreach($x as $p) // fails with invalid type
>>> {
>>> }
>>> }
>>> ?>
>>> ---------
>>>
>>> <?php
>>> $x=array();
>>> global $x;
>>> function foo()
>>> {
>>> global $x;
>>> foreach($x as $p) // works??
>>> {
>>> }
>>> }
>>> ?>
>>> ---------
>>> This behaviour seems only limited to arrays...
>>
>> No (unless there's a bug in a particular PHP version). Your first code
>> sample works fine without even a notice.
>>
>
> It doesn't here, but the code is being 'eval'ed' ...
>
Which is an important fact you conveniently forgot to add. The problem
is not in the code. The problem is in your design of the scripts.
First rule - eval() is nasty and should not be used.
Second rule - see first rule.
>> Using a global statement in the global scope is not wrong, but it's
>> useless in this case. See the PHP manual on global[1], especially the
>> note at the end of the section.
>
> In this case its the difference between the program working and not
> working.
>
It's the difference between a good design and a TNP design.
>
>>
>> [1]
>> <http://www.php.net/language.variables.scope.php#language.variables.scope.global>
>>
>>
>
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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