[PHP] Re: Variable Variables and Super Global Arrays

2008-10-11 Thread ANR Daemon
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 <[EMAIL PROTECTED]>


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



[PHP] Re: Variable variables

2006-01-24 Thread James Benson



Mark Steudel wrote:

I was wondering if you could create variable variables for objects, please
see examples below, Im having problems getting it to work.

$data['fieldname'] = foo;
 
// without variable variables

$res =& $db->query( "SELECT foo FROM table" );
 
while( $res->fetchInto( $db_data ) )

{
echo $db_data->foo; // pretend this echos bar
}
 
 
 // with variable variables

$varVar = '$db_data->'.$data['fieldname']; // should be $db_data->foo
 



Try using double quotes, ie.

$varVar = "$db_data->".$data['fieldname'];




James

-

http://www.ciwcertified.com - Master CIW Designer
http://www.zend.com - Zend Certified Engineer


http://www.jamesbenson.co.uk

-

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



[PHP] Re: Variable variables

2004-08-28 Thread M. Sokolewicz
Janbro wrote:
Hi List,

I'm  using PHP5 with global variables off. I've got  around 20 dynamically
generated forms with a total of 300 different variables sent thru these
forms. I'd like to use variable variables, but according to the manual this
is not possible.
Now comes my Questoin, how do I receive my variables  which have the form
$a_123 or $a_124[]. Is there a workaround for PHP5 or PHP in general?
euh, if you're gonna do that automatically, then that's *exactly* the 
same as setting register_globals = On.

Who do I make  $data = $_REQUEST['a_123'] work ???
what's wrong with that? if it gets sent under the name 'a_123' then 
that'll work fine I don't see your problem :S

 I'd hate to set global
variables to on, as I'm dealing with sensitive data.

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


[PHP] Re: Variable Variables and Mulitdimensional Arrays

2002-03-16 Thread Joe Webster

You seem to have three different ideas/questions... let me attempt to answer
them:

> Hi. I want to be able to access a key in a multidimensional array at some
> depth "n" without knowing before runtime what the keys are.

let's take a multidimensional array $x
$x = array(
"somevar",
array(
"otherval",
"evenmore"
)
);

echo $x[0]; should print 'somevar'
echo $x[1]; should print 'Array'
echo $x[1][0]; should print 'otherval'
echo $x[1][1]; should print 'evenmore'

>
> I thought this might be possible using variable variables. Here's some
> sample code using variable variables and multidimensional arrays:
> $y = 'a';
> $z = 'b';
> $t = 'c';
> $x = array("a"=>array("b"=>array("c"=>TRUE)));
>

> // I want to be able to concatenate the array indexes into one variable
> variable. This would be done in a loop at runtime.
if you want to concat all the key's of an array with a loop you could do:

reset($x); //just to make sure we are at the first key
while(list($key,$val) = each($x)){
$my_keys .= $key
}
echo $my_keys;

should result in: (using $x from my code above)

1 (I think it might even come out as 01 -- but probally 1 since it will be
treated as a int maybe =) )

>
> Any help would greatly be appreciated,
>
> Charlie
>
>

Hope that helps, still not sure what your question was or if i answered it
;)

-Joe



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




[PHP] Re: variable variables and eval

2001-08-13 Thread Richard Lynch

> i have come across a strange problem with variable variables. Basicly i'm
> doing the following and its not working:
>
> $section = 'data["SITE"][0]["NAME"][0]';
> $pData = 'My Site.';
> ${sprintf('$%s', $section)}.=$pData;
>
> but it is not working. But if i do this:
>
> eval('$'.$section.'.="'.addslashes($pData).'";');
>
> it works and all is well. I don't really want to use eval() and just
> wanted to see if anybody has any ideas why the above doesn't work.

Why is the sprintf in there?...

Try this:

${$section} .= $pData;

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]