Skip to main content
Inspiring
March 17, 2008
Question

PHP Globals?

  • March 17, 2008
  • 3 replies
  • 264 views
I'm looking at a script that has this line -

$GLOBALS[$key] = $val;

Am I remembering something bad about such usages? Or am I thinking of
register_globals?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


This topic has been closed for replies.

3 replies

Inspiring
March 17, 2008
Murray *ACE* escreveu:
> I'm looking at a script that has this line -
>
> $GLOBALS[$key] = $val;
>
> Am I remembering something bad about such usages? Or am I thinking of
> register_globals?
>
---------
Useful script:

<?php

// GLOBALS

echo "<pre>";
print_r ($GLOBALS);
echo "</pre>";

# OTHER PREDEFINED VARIABLES

echo "<pre>";
print_r ($_SERVER);
echo "</pre>";

echo "<pre>";
print_r ($HTTP_SERVER_VARS);
echo "</pre>";

?>
-----
zerof
Inspiring
March 17, 2008
.oO(Murray *ACE*)

>I'm looking at a script that has this line -
>
>$GLOBALS[$key] = $val;
>
>Am I remembering something bad about such usages?

Yes, using global variables is bad style. The better ways would be OOP
or to pass the required values to the function.

>Or am I thinking of
>register_globals?

Something different.

Micha
Inspiring
March 17, 2008
Murray *ACE* wrote:
> I'm looking at a script that has this line -
>
> $GLOBALS[$key] = $val;
>
> Am I remembering something bad about such usages?

It depends how the value is originally obtained, and if it has been
sanitized and validated. In general, though, I would steer away from its
use.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/