Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP Globals?

LEGEND ,
Mar 17, 2008 Mar 17, 2008
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
==================


TOPICS
Server side applications
266
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 17, 2008 Mar 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 17, 2008 Mar 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 17, 2008 Mar 17, 2008
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines