Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

$GLOBALS

0 views
Skip to first unread message

Mike

unread,
Jun 11, 2003, 4:16:39 PM6/11/03
to php-w...@lists.php.net
When running the following code:

foreach($GLOBALS['photo'] as $photo)

I get:

Warning: Invalid argument supplied for foreach() on line 63

Would register globals have to be on for this code to work? Am I using the
$GLOBALS clause wrong? It would seem to me that this should work since you
can use post in the same fashion.
ie: foreach($_POST['photo'] as $photo)

~ Mike


Adam Goossens

unread,
Jun 12, 2003, 8:13:28 PM6/12/03
to php-w...@lists.php.net
Mike,

The $GLOBALS array contains references to all variables defined in the global
scope. By using the keyword global, you define a variable in the global scope
(and then make it accessible through $GLOBALS).

The superglobals (eg _POST, _GET, etc) don't get this automatically, because
they are "scopeless".

It would only work if you used the following code beforehand:

global $_POST['photo'];

hth.
--
Adam Goossens

=======================================

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

Adam Goossens

unread,
Jun 12, 2003, 11:36:30 PM6/12/03
to php-w...@lists.php.net
Oh, and to answer your original question: yes, as far as I am aware
register_globals would have to be on for that code to work.

--
Adam Goossens

Dvdmandt

unread,
Jun 13, 2003, 2:38:31 AM6/13/03
to php-w...@lists.php.net
Hmm... I think the first part of foreach should be an array... So, more
like
foreach($GLOBALS as $photo)... Unless photo is an array containing photos...
However, how to make a variable become global, I'm not sure of...
"Mike" <mi...@homemarketing.net> skrev i meddelandet
news:2003061120164...@pb1.pair.com...

Dj Dust

unread,
Jun 14, 2003, 9:34:25 AM6/14/03
to php-w...@lists.php.net
hiya

I've been tearing my hair out for 2 days now trying to get this to work and
I'm sure the answer has gotta be pretty simple...

I'm using PHP for the first time and have got some pages uploaded to my live
site and they work like a dream - the problem is that they won't work
locally using PHPdev.

Every page on site uses the following include code on every page:

<?php
include($DOCUMENT_ROOT . "/include/header.htm");
?>

the theory is that no matter where you are in the site hierarchy (there's a
lot of directories within directories) it should still work.

Like I said, it DOES work fine when I upload the pages to my ISP but only
the top level files of the site work locally. If you go down into
sub-directories I get the following error:

"Warning: Failed opening '/include/header.htm' for inclusion
(include_path='.;C:/phpdev/php/includes;C:/phpdev/php/class') in
c:\phpdev\www\curve-online.co.uk\discography\official.php on line 12"

Any idea how I can get my local server working the same as my ISP server?

cheers

daz


Dash McElroy

unread,
Jun 14, 2003, 3:16:07 PM6/14/03
to dj dust, php-w...@lists.php.net
daz,

This should be easy enough. First, have you checked to see if
register_globals is on or off on your local machine? It defaults to off,
so $DOCUMENT_ROOT would become $_SERVER['DOCUMENT_ROOT'].

Check a phpinfo() screen and see what variables are different between your
host and your local box. Just a simple file with only the following line:

<?php phpinfo(); ?>

will suffice.

Another thing you could do is to declare a php include directory and stuff
all your include files into there.

-Dash

> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Dvdmandt

unread,
Jun 14, 2003, 3:37:55 PM6/14/03
to php-w...@lists.php.net
Oh, I think you have the register_globals problem... Search the manual for
'register_globals' for more info...
"Dj Dust" <djd...@ntlworld.com> skrev i meddelandet
news:000801c33279$abd88030$782f6851@dustrj5f35bjm2...

Dvdmandt

unread,
Jun 14, 2003, 3:39:10 PM6/14/03
to php-w...@lists.php.net
Assuming it's not a downloaded script that is...
"Dash McElroy" <p...@l1te.net> skrev i meddelandet
news:Pine.NEB.4.53.03...@shell.sasquatch.com...

Dj Dust

unread,
Jun 16, 2003, 4:27:31 PM6/16/03
to php-w...@lists.php.net
thanks for the reply.

> This should be easy enough. First, have you checked to see if
> register_globals is on or off on your local machine? It defaults to off,
> so $DOCUMENT_ROOT would become $_SERVER['DOCUMENT_ROOT'].

yep, it was set to 'off' so I've changed all the includes now so that they
look like this:

<?php
include($_SERVER['DOCUMENT_ROOT'] . "/include/header.htm");
?>

again, they work fine on the live site but still not locally :(


> Check a phpinfo() screen and see what variables are different between your
> host and your local box. Just a simple file with only the following line:
>
> <?php phpinfo(); ?>
>
> will suffice.
>

well, here's the page I put up live:

http://www.curve-online.co.uk/test.php

I notice the live version of PHP is version 4.1.2. I'm running 4.2.3
locally. Could this make a difference?


> Another thing you could do is to declare a php include directory and stuff
> all your include files into there.

erm, the live one is set to " .: "

I tried adding it to the local include_path (on C:/windows/php.ini) so that
it said

" . ; .: ;C:/phpdev/php/includes;C:/phpdev/php/class "

but still no joy - this is driving me really barmy now. Am I still missing
something?

cheers

daz

0 new messages