Re: Creating Dynamic Variables

From: Date: Fri, 19 Jul 2002 01:22:14 +0000
Subject: Re: Creating Dynamic Variables
Groups: php.general 
Request: Send a blank email to php-general+get-108401@lists.php.net to get a copy of this message
>Hello, I have captured variables from any HTML that is POSTed to me from a >'foreach' clause. Now, possibly in this foreach clause I want to register >these name/value pairs into a session var. I have tried : >session_start(); >foreach ($HTTP_POST_VARS as $name=>$value) { >$name=$value; >session_register(name); //without the $ >} >and get nothing. That's because you are registering 'name', which is to say $name, rather that whatever is *inside* of $name... Okay, the docs *DO* point out that you need to use the name of the variable for session_register, not the varible itself, but $name *HOLDS* the name of your variable. In other words, consider this: <?php $name = 'foo'; $foo = 42; session_register('foo'); #RIGHT session_register($foo); #WRONG session_register($name); #RIGHT, same as session_register('foo') since $name == 'foo' session_register('name'); #WRONG, that's registering $name, not $foo ?> Hope that makes sense. Oh, and use error_reporting(E_ALL) to crank up your warning messages. You'll end up writing better code because of it. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#108401) next »