PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Variable Variables and Super Global Arrays
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Variable Variables and Super Global Arrays

Réponse
 
LinkBack Outils de la discussion
Vieux 11/10/2008, 00h50   #1
daniel danon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Variable Variables and Super Global Arrays

Hi, I was wondering,
By php.net manual, "Please note that variable variables cannot be used with
PHP's Superglobal arrays within functions or class methods". Is there any
way to override this problem? Just the not nice eval("return $variable");?

and in simple words - is there any way to make the following code work:

$varname = "\$_SERVER['REMOTE_ADDR']";
$varvalue = $$varname;


?

  Réponse avec citation
Vieux 12/10/2008, 05h52   #2
ANR Daemon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Variable Variables and Super Global Arrays

Greetings, "daniel danon".
In reply to Your message dated Saturday, October 11, 2008, 2:50:34,

> By php.net manual, "Please note that variable variables cannot be used with
> PHP's Superglobal arrays within functions or class methods". Is there any
> way to override this problem? Just the not nice eval("return $variable");?


> and in simple words - is there any way to make the following code work:


> $varname = "\$_SERVER['REMOTE_ADDR']";
> $varvalue = $$varname;



First of all, why you need it to work?
Explain real case please.


--
Sincerely Yours, ANR Daemon <anrdaemon@freemail.ru>

  Réponse avec citation
Vieux 12/10/2008, 10h21   #3
Richard Heyes
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Variable Variables and Super Global Arrays

> $varname = "\$_SERVER['REMOTE_ADDR']";
> $varvalue = $$varname;


That's wrong. Offhand you'll end up printing a string. I tried this:

<?php
$a = 365;
$b = 366;

$var = $_GET['var'];

echo $$var;
?>

And it was fine.

--
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org
  Réponse avec citation
Vieux 12/10/2008, 17h40   #4
Micah Gersten
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Variable Variables and Super Global Arrays

That's fine as a test, but you never want to get a variable name from a
URL in practice.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Richard Heyes wrote:
>> $varname = "\$_SERVER['REMOTE_ADDR']";
>> $varvalue = $$varname;
>>

>
> That's wrong. Offhand you'll end up printing a string. I tried this:
>
> <?php
> $a = 365;
> $b = 366;
>
> $var = $_GET['var'];
>
> echo $$var;
> ?>
>
> And it was fine.
>
>

  Réponse avec citation
Vieux 12/10/2008, 18h12   #5
Richard Heyes
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Variable Variables and Super Global Arrays

> That's fine as a test, but you never want to get a variable name from a
> URL in practice.


Of course you can, as long as it's sanitized and checked.

--
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org
  Réponse avec citation
Vieux 12/10/2008, 19h40   #6
Micah Gersten
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Variable Variables and Super Global Arrays

I mean that it is open for hacking if you pass a variable name through a
URL.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



daniel danon wrote:
> What do you mean?
>
> On Sun, Oct 12, 2008 at 5:40 PM, Micah Gersten <micah@onshore.com
> <mailto:micah@onshore.com>> wrote:
>
> That's fine as a test, but you never want to get a variable name
> from a
> URL in practice.
>
> Thank you,
> Micah Gersten
> onShore Networks
> Internal Developer
> http://www.onshore.com
>
>
>
> Richard Heyes wrote:
> >> $varname = "\$_SERVER['REMOTE_ADDR']";
> >> $varvalue = $$varname;
> >>

> >
> > That's wrong. Offhand you'll end up printing a string. I tried this:
> >
> > <?php
> > $a = 365;
> > $b = 366;
> >
> > $var = $_GET['var'];
> >
> > echo $$var;
> > ?>
> >
> > And it was fine.
> >
> >

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 20h18.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10563 seconds with 14 queries