Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Mladen Gogala Newsgroups: comp.lang.php Subject: Re: weird global issue Date: Sun, 23 Feb 2014 22:09:06 +0000 (UTC) Organization: A noiseless patient Spider Lines: 62 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 23 Feb 2014 22:09:06 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="9329a606497bb546bacd1416e46e9713"; logging-data="9916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Xj/5GRlUTz/tOusCqWQlc" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:K9VkAmGTxaodEx5jmwznha7LLJQ= Xref: csiph.com comp.lang.php:12910 On Sun, 23 Feb 2014 18:33:52 +0000, The Natural Philosopher wrote: > Consider > function foo() > { > global $x; > foreach($x as $p) // fails with invalid type > { > } > } > ?> > --------- > > 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 [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