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


Groups > comp.lang.php > #12910

Re: weird global issue

From Mladen Gogala <gogala.mladen@gmail.com>
Newsgroups comp.lang.php
Subject Re: weird global issue
Date 2014-02-23 22:09 +0000
Organization A noiseless patient Spider
Message-ID <pan.2014.02.23.22.09.06@gmail.com> (permalink)
References <ledeug$a34$1@news.albasani.net>

Show all headers | View raw


On Sun, 23 Feb 2014 18:33:52 +0000, 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...

Which version of PHP? I copied your code almost literally and it works 
flawlessly:
[mgogala@medo ~]$ cat /tmp/ttt.php
#!/usr/bin/php
<?php
$x=array(1,2,3);

function foo()
{
global $x;
foreach($x as $p) // fails with invalid type
    {
      print "$p\n";
    }
}
foo();
?>

[mgogala@medo ~]$ /tmp/ttt.php
1
2
3

mgogala@medo ~]$ php -v
PHP 5.5.9 (cli) (built: Feb 18 2014 15:01:31) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
[mgogala@medo ~]$ 

It's Linux, F20. 

-- 
Mladen Gogala
The Oracle Whisperer
http://mgogala.byethost5.com

Back to comp.lang.php | Previous | Next — Previous 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