Re: [PHP] Variable variables into an array.

2010-08-11 Thread Richard Quadling
On 10 August 2010 18:08, Andrew Ballard aball...@gmail.com wrote:
 On Tue, Aug 10, 2010 at 12:23 PM, Richard Quadling rquadl...@gmail.com 
 wrote:
 On 10 August 2010 16:49, Jim Lucas li...@cmsws.com wrote:
 Richard Quadling wrote:

 Hi.

 Quick set of eyes needed to see what I've done wrong...

 The following is a reduced example ...

 ?php
 $Set = array();
 $Entry = 'Set[1]';
 $Value = 'Assigned';
 $$Entry = $Value;
 print_r($Set);
 ?

 The output is an empty array.

 Examining $GLOBALS, I end up with an entries ...

    [Set] = Array
        (
        )

    [Entry] = Set[1]
    [Value] = Assigned
    [Set[1]] = Assigned


 According to http://docs.php.net/manual/en/language.variables.basics.php,
 a variable named Set[1] is not a valid variable name. The [ and ] are
 not part of the set of valid characters.

 In testing all the working V4 and V5 releases I have, the output is
 always an empty array, so it looks like it is me, but the invalid
 variable name is an issue I think.

 Regards,

 Richard.

 NOTE: The above is a simple test. I'm trying to map in nested data to
 over 10 levels.

 For something like this, a string that looks like a nested array reference,
 you might need to involve eval for it to derive that nested array.


 I'm happy with that.

 It seems variable variables can produce variables that do not follow
 the same naming limitations as normal variables.


 It would seem so. If eval() works, can you rearrange the strings a
 little to make use of parse_str() and avoid the use of eval()?

 Andrew


php -r parse_str('a[1][2][3]=richard quadling'); var_dump($a);

outputs ...

array(1) {
  [1]=
  array(1) {
[2]=
array(1) {
  [3]=
  string(16) richard quadling
}
  }
}

Perfect.

Thanks.

-- 
Richard Quadling.

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



RE: [PHP] Variable variables into an array.

2010-08-11 Thread Bob McConnell
From: Richard Quadling

 Quick set of eyes needed to see what I've done wrong...
 
 The following is a reduced example ...
 
 ?php
 $Set = array();
 $Entry = 'Set[1]';
^^
Shouldn't that be $Set[1]?

 $Value = 'Assigned';
 $$Entry = $Value;
 print_r($Set);
 ?

Bob McConnell

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



Re: [PHP] Variable variables into an array.

2010-08-11 Thread Richard Quadling
On 11 August 2010 13:58, Bob McConnell r...@cbord.com wrote:
 From: Richard Quadling

 Quick set of eyes needed to see what I've done wrong...

 The following is a reduced example ...

 ?php
 $Set = array();
 $Entry = 'Set[1]';
            ^^
 Shouldn't that be $Set[1]?

 $Value = 'Assigned';
 $$Entry = $Value;
 print_r($Set);
 ?

 Bob McConnell


No.

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



Re: [PHP] Variable variables into an array.

2010-08-10 Thread Jim Lucas

Richard Quadling wrote:

Hi.

Quick set of eyes needed to see what I've done wrong...

The following is a reduced example ...

?php
$Set = array();
$Entry = 'Set[1]';
$Value = 'Assigned';
$$Entry = $Value;
print_r($Set);
?

The output is an empty array.

Examining $GLOBALS, I end up with an entries ...

[Set] = Array
(
)

[Entry] = Set[1]
[Value] = Assigned
[Set[1]] = Assigned


According to http://docs.php.net/manual/en/language.variables.basics.php,
a variable named Set[1] is not a valid variable name. The [ and ] are
not part of the set of valid characters.

In testing all the working V4 and V5 releases I have, the output is
always an empty array, so it looks like it is me, but the invalid
variable name is an issue I think.

Regards,

Richard.

NOTE: The above is a simple test. I'm trying to map in nested data to
over 10 levels.


For something like this, a string that looks like a nested array 
reference, you might need to involve eval for it to derive that nested 
array.


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



Re: [PHP] Variable variables into an array.

2010-08-10 Thread Richard Quadling
On 10 August 2010 16:49, Jim Lucas li...@cmsws.com wrote:
 Richard Quadling wrote:

 Hi.

 Quick set of eyes needed to see what I've done wrong...

 The following is a reduced example ...

 ?php
 $Set = array();
 $Entry = 'Set[1]';
 $Value = 'Assigned';
 $$Entry = $Value;
 print_r($Set);
 ?

 The output is an empty array.

 Examining $GLOBALS, I end up with an entries ...

    [Set] = Array
        (
        )

    [Entry] = Set[1]
    [Value] = Assigned
    [Set[1]] = Assigned


 According to http://docs.php.net/manual/en/language.variables.basics.php,
 a variable named Set[1] is not a valid variable name. The [ and ] are
 not part of the set of valid characters.

 In testing all the working V4 and V5 releases I have, the output is
 always an empty array, so it looks like it is me, but the invalid
 variable name is an issue I think.

 Regards,

 Richard.

 NOTE: The above is a simple test. I'm trying to map in nested data to
 over 10 levels.

 For something like this, a string that looks like a nested array reference,
 you might need to involve eval for it to derive that nested array.


I'm happy with that.

It seems variable variables can produce variables that do not follow
the same naming limitations as normal variables.



-- 
Richard Quadling.

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



Re: [PHP] Variable variables into an array.

2010-08-10 Thread Andrew Ballard
On Tue, Aug 10, 2010 at 12:23 PM, Richard Quadling rquadl...@gmail.com wrote:
 On 10 August 2010 16:49, Jim Lucas li...@cmsws.com wrote:
 Richard Quadling wrote:

 Hi.

 Quick set of eyes needed to see what I've done wrong...

 The following is a reduced example ...

 ?php
 $Set = array();
 $Entry = 'Set[1]';
 $Value = 'Assigned';
 $$Entry = $Value;
 print_r($Set);
 ?

 The output is an empty array.

 Examining $GLOBALS, I end up with an entries ...

    [Set] = Array
        (
        )

    [Entry] = Set[1]
    [Value] = Assigned
    [Set[1]] = Assigned


 According to http://docs.php.net/manual/en/language.variables.basics.php,
 a variable named Set[1] is not a valid variable name. The [ and ] are
 not part of the set of valid characters.

 In testing all the working V4 and V5 releases I have, the output is
 always an empty array, so it looks like it is me, but the invalid
 variable name is an issue I think.

 Regards,

 Richard.

 NOTE: The above is a simple test. I'm trying to map in nested data to
 over 10 levels.

 For something like this, a string that looks like a nested array reference,
 you might need to involve eval for it to derive that nested array.


 I'm happy with that.

 It seems variable variables can produce variables that do not follow
 the same naming limitations as normal variables.


It would seem so. If eval() works, can you rearrange the strings a
little to make use of parse_str() and avoid the use of eval()?

Andrew

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



Re: [PHP] Variable Variables and Super Global Arrays

2008-10-12 Thread Richard Heyes
 $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

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



Re: [PHP] Variable Variables and Super Global Arrays

2008-10-12 Thread Micah Gersten
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



Re: [PHP] Variable Variables and Super Global Arrays

2008-10-12 Thread Richard Heyes
 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

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



Re: [PHP] Variable Variables and Super Global Arrays

2008-10-12 Thread Micah Gersten
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 [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] 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



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



Re: [PHP] Variable variables and references

2007-03-14 Thread Robert Cummings
On Wed, 2007-03-14 at 12:39 +0100, Jochem Maas wrote:
 Richard Lynch wrote:
  On Sat, March 10, 2007 6:28 am, Dave Goodchild wrote:
  Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I
  think
  it's a great book, I am confused about variable variables and
  references -
  not the mechanics, just where you would use them.
 
  The subject of variable variables is explained but no examples are
  given as
  to why and where you would utilise them.
  
  99% of the time, using variable variables means you screwed up and
  should have used an array. :-)
 
 you could change that adage to this and it would still be true ;-) :
 
 75% of the time, using fill in a blank means you screwed up and
 should have used an array. :-)
 
   - Lynchism #3

I'm certain it conforms to the golden ratio :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Variable variables and references

2007-03-12 Thread Richard Lynch
On Sat, March 10, 2007 6:28 am, Dave Goodchild wrote:
 Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I
 think
 it's a great book, I am confused about variable variables and
 references -
 not the mechanics, just where you would use them.

 The subject of variable variables is explained but no examples are
 given as
 to why and where you would utilise them.

99% of the time, using variable variables means you screwed up and
should have used an array. :-)

The 1% remaining is something that should be attempted only by
experts, so you'll know when you get there that you need it.

 As for references, the examples given with regard to passing and
 returning
 by reference in functions is clear, but no real examples are given as
 to
 when this would be a preferred approcah - in fact, the authors stress
 that
 due to PHP's copy-on-write mechanism, it is not a frequently-used
 approcah.

In PHP5, the whole reference thing changed all around.

What version is the book targetted at, and what version are you running?

 So my question - are there any 'classic' situations in which either
 should
 be used, and where and when do you guys use them in your real-world
 efforts?

I don't even use OOP in PHP, much less OOP.

I only used variable variables when I was young and foolish.

Well, younger and more foolish.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Variable variables and references

2007-03-11 Thread Martin Alterisio

2007/3/10, Dave Goodchild [EMAIL PROTECTED]:


Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I
think
it's a great book, I am confused about variable variables and references -
not the mechanics, just where you would use them.

The subject of variable variables is explained but no examples are given
as
to why and where you would utilise them.



There really aren't useful and you're well without knowing they even exist.
In my opinion they harm code readibility, so they shouldn't be used,
especially if what you're trying to do can be achieved in some other way.

There is a special case where I found them useful. If you play competitions
like the sort of codegolf, they can be used to reduce your code by a few
characters by doing some really nasty things.

As for references, the examples given with regard to passing and returning

by reference in functions is clear, but no real examples are given as to
when this would be a preferred approcah - in fact, the authors stress that
due to PHP's copy-on-write mechanism, it is not a frequently-used
approcah.



References are useful to simulate PHP5 objects behaviour in PHP4. They can
be useful in many ways but I've found myself having too many troubles when
overusing them, segfaults and the sort...

So my question - are there any 'classic' situations in which either should

be used, and where and when do you guys use them in your real-world
efforts?
--
http://www.web-buddha.co.uk



Re: [PHP] Variable variables and references

2007-03-10 Thread Tijnema !

I must say, in all the years i am programming with PHP (about 5-6 years) i
NEVER used references.
So i don't find it useful, but well, if you want to give your variable
content more than one name, you can :)

I think you just need to start programming now, keeping in mind they are
available, but don't use them if it isn't needed.

Tijnema


On 3/10/07, Dave Goodchild [EMAIL PROTECTED] wrote:


Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I
think
it's a great book, I am confused about variable variables and references -
not the mechanics, just where you would use them.

The subject of variable variables is explained but no examples are given
as
to why and where you would utilise them.

As for references, the examples given with regard to passing and returning
by reference in functions is clear, but no real examples are given as to
when this would be a preferred approcah - in fact, the authors stress that
due to PHP's copy-on-write mechanism, it is not a frequently-used
approcah.

So my question - are there any 'classic' situations in which either should
be used, and where and when do you guys use them in your real-world
efforts?
--
http://www.web-buddha.co.uk



Re: [PHP] Variable variables and references

2007-03-10 Thread Matt Carlson
I've used variable variables probably 5 times in 2 years.  They are great when 
you need them, but don't usually have a day-to-day use for them.

Here is some sample code of the last time I used it.


if(isset($$key))
{
print($$key);
continue;
} else {
$iquery = SELECT * FROM `.ROSTER_ITEMSTABLE.` WHERE 
`item_name` = '.$iname.' AND `member_id` = '.$row['member_id'].';
$iresult = $wowdb-query($iquery);
$idata = $wowdb-fetch_assoc($iresult);
$item = new item($idata);
$$key = $item-out();
print $$key;
}

Basically, this is in a for-each loop, that steps through a list of keys for 
certain dungeons in World of Warcraft.  Instead of putting the data into an 
array, I used variable variables to stick the data into a single variable.  The 
way it works is  $key = 'DM'; $$key = $data;  The literal translation for $$key 
is $DM once the code executes.

Hope this helps.

- Original Message 
From: Dave Goodchild [EMAIL PROTECTED]
To: PHP-General php-general@lists.php.net
Sent: Saturday, March 10, 2007 5:28:57 AM
Subject: [PHP] Variable variables and references

Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I think
it's a great book, I am confused about variable variables and references -
not the mechanics, just where you would use them.

The subject of variable variables is explained but no examples are given as
to why and where you would utilise them.

As for references, the examples given with regard to passing and returning
by reference in functions is clear, but no real examples are given as to
when this would be a preferred approcah - in fact, the authors stress that
due to PHP's copy-on-write mechanism, it is not a frequently-used approcah.

So my question - are there any 'classic' situations in which either should
be used, and where and when do you guys use them in your real-world efforts?
-- 
http://www.web-buddha.co.uk




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



Re: [PHP] Variable variables and references

2007-03-10 Thread Tijnema !

On 3/10/07, Matt Carlson [EMAIL PROTECTED] wrote:


I've used variable variables probably 5 times in 2 years.  They are great
when you need them, but don't usually have a day-to-day use for them.

Here is some sample code of the last time I used it.


if(isset($$key))
   {
   print($$key);
   continue;
   } else {
   $iquery = SELECT * FROM `.ROSTER_ITEMSTABLE.` WHERE
`item_name` = '.$iname.' AND `member_id` = '.$row['member_id'].';
   $iresult = $wowdb-query($iquery);
   $idata = $wowdb-fetch_assoc($iresult);
   $item = new item($idata);
   $$key = $item-out();
   print $$key;
   }

Basically, this is in a for-each loop, that steps through a list of keys
for certain dungeons in World of Warcraft.  Instead of putting the data into
an array, I used variable variables to stick the data into a single
variable.  The way it works is  $key = 'DM'; $$key = $data;  The literal
translation for $$key is $DM once the code executes.

Hope this helps.



In this case i should use an array, i think it's easier to use an array...
Array in an array in an array :)

But ofcourse sometimes you might (think you) need it.

Tijnema

- Original Message 

From: Dave Goodchild [EMAIL PROTECTED]
To: PHP-General php-general@lists.php.net
Sent: Saturday, March 10, 2007 5:28:57 AM
Subject: [PHP] Variable variables and references

Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I
think
it's a great book, I am confused about variable variables and references -
not the mechanics, just where you would use them.

The subject of variable variables is explained but no examples are given
as
to why and where you would utilise them.

As for references, the examples given with regard to passing and returning
by reference in functions is clear, but no real examples are given as to
when this would be a preferred approcah - in fact, the authors stress that
due to PHP's copy-on-write mechanism, it is not a frequently-used
approcah.

So my question - are there any 'classic' situations in which either should
be used, and where and when do you guys use them in your real-world
efforts?
--
http://www.web-buddha.co.uk




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




Re: [PHP] Variable variables and references

2007-03-10 Thread M.Sokolewicz
I'd agree with Tijnema! here, variable variables aren't really of any 
use here. However, a classic snippet of code is where one emulates 
register_globals functionality in a non-register_globals environment 
(not a good idea to do this btw, unless you know what you're doing and 
don't have any other way around it):

foreach($_POST as $key=$val) {
$$key = $val;
}
thus creating all
$image,$whatever,$and,$some,$more variables magically for you.

- tul

Tijnema ! wrote:

On 3/10/07, Matt Carlson [EMAIL PROTECTED] wrote:


I've used variable variables probably 5 times in 2 years.  They are great
when you need them, but don't usually have a day-to-day use for them.

Here is some sample code of the last time I used it.


if(isset($$key))
   {
   print($$key);
   continue;
   } else {
   $iquery = SELECT * FROM `.ROSTER_ITEMSTABLE.` WHERE
`item_name` = '.$iname.' AND `member_id` = '.$row['member_id'].';
   $iresult = $wowdb-query($iquery);
   $idata = $wowdb-fetch_assoc($iresult);
   $item = new item($idata);
   $$key = $item-out();
   print $$key;
   }

Basically, this is in a for-each loop, that steps through a list of keys
for certain dungeons in World of Warcraft.  Instead of putting the 
data into

an array, I used variable variables to stick the data into a single
variable.  The way it works is  $key = 'DM'; $$key = $data;  The literal
translation for $$key is $DM once the code executes.

Hope this helps.



In this case i should use an array, i think it's easier to use an array...
Array in an array in an array :)

But ofcourse sometimes you might (think you) need it.

Tijnema

- Original Message 

From: Dave Goodchild [EMAIL PROTECTED]
To: PHP-General php-general@lists.php.net
Sent: Saturday, March 10, 2007 5:28:57 AM
Subject: [PHP] Variable variables and references

Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I
think
it's a great book, I am confused about variable variables and 
references -

not the mechanics, just where you would use them.

The subject of variable variables is explained but no examples are given
as
to why and where you would utilise them.

As for references, the examples given with regard to passing and 
returning

by reference in functions is clear, but no real examples are given as to
when this would be a preferred approcah - in fact, the authors stress 
that

due to PHP's copy-on-write mechanism, it is not a frequently-used
approcah.

So my question - are there any 'classic' situations in which either 
should

be used, and where and when do you guys use them in your real-world
efforts?
--
http://www.web-buddha.co.uk




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






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



Re: [PHP] Variable variables

2004-08-28 Thread Marek Kilimajer
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?

Who do I make  $data = $_REQUEST['a_123'] work ??? I'd hate to set global
variables to on, as I'm dealing with sensitive data.
$form_var = 'a_123';
$data = $_REQUEST[$form_var];
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Variable variables

2004-08-28 Thread Justin Patrin
On Sat, 28 Aug 2004 11:43:13 +0200, JanBro [EMAIL PROTECTED] 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?
 
 Who do I make  $data = $_REQUEST['a_123'] work ??? I'd hate to set global
 variables to on, as I'm dealing with sensitive data.
 

Your question makes absolutely no sense. You can do $_REQUEST['a_123']
just fine. If what you want is to loop through them...
foreach($_REQUEST as $key = $val) {
  //
}

or

foreach($variableNames as $var) {
  $_REQUEST[$var]
}

-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

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



Re: [PHP] Variable Variables adn Superglobals

2004-08-04 Thread Justin Patrin
On Wed, 04 Aug 2004 23:15:03 +0200, ARico [EMAIL PROTECTED] wrote:
 Using Variable Variables works fine inside functions for global
 defined variables if you declare them as global inside the function.
 Suprinsingly, it does not seem to work with superglobals. Take the
 following example:
 
 // code 
 
 ?php
 $glob_var=Var 1;
 
 $var_glob_var=glob_var;
 $var_ENV=_ENV;
 
 echo $_ENV[OS],\n;
 echo $glob_var,\n\n;
 
 echo $var_glob_var,\n;
 echo $var_ENV,\n\n;
 
 echo $$var_glob_var,\n;
 echo ${$var_ENV}[OS],\n\n;
 
 foo1($var_glob_var);
 foo2($var_glob_var);
 foo3();
 foo4();
 foo5($var_ENV);
 foo6($var_ENV);
 foo7();
 foo8();
 foo9();
 
 function foo1($arg){
 echo --- In foo1 --\n;
 echo $arg,\n;
 echo $$arg,\n;
 echo --\n;
 }
 function foo2($arg){
 global $glob_var;
 
 echo --- In foo2 --\n;
 echo $arg,\n;
 echo $$arg,\n;
 echo --\n;
 }
 function foo3(){
 $arg=glob_var;
 echo --- In foo3 --\n;
 echo $arg,\n;
 echo $$arg,\n;
 echo --\n;
 }
 function foo4(){
 global $glob_var;
 
 $arg=glob_var;
 echo --- In foo4 --\n;
 echo $arg,\n;
 echo $$arg,\n;
 echo --\n;
 }
 function foo5($arg){
 echo --- In foo5 --\n;
 echo $arg,\n;
 echo ${$arg}[OS],\n;
 echo --\n;
 }
 function foo6($arg){
 global $_ENV;
 
 echo --- In foo6 --\n;
 echo $arg,\n;
 echo ${$arg}[OS],\n;
 echo --\n;
 }
 function foo7(){
 $arg=_ENV;
 
 echo --- In foo7 --\n;
 echo $arg,\n;
 echo ${$arg}[OS],\n;
 echo --\n;
 }
 function foo8(){
 global $_ENV;
 $arg=_ENV;
 
 echo --- In foo8 --\n;
 echo $arg,\n;
 echo ${$arg}[OS],\n;
 echo --\n;
 }
 function foo9(){
 echo --- In foo9 --\n;
 echo $_ENV[OS],\n;
 echo --\n;
 }
 ?
 
 // Output /
 
 Windows_NT
 Var 1
 
 glob_var
 _ENV
 
 Var 1
 Windows_NT
 
 --- In foo1 --
 glob_var
 
 --
 --- In foo2 --
 glob_var
 Var 1
 --
 --- In foo3 --
 glob_var
 
 --
 --- In foo4 --
 glob_var
 Var 1
 --
 --- In foo5 --
 _ENV
 
 --
 --- In foo6 --
 _ENV
 
 --
 --- In foo7 --
 _ENV
 
 --
 --- In foo8 --
 _ENV
 
 --
 --- In foo9 --
 Windows_NT
 --
 
 // Version //
 
 PHP 4.3.7 (cgi-fcgi) (built: Jun  2 2004 15:49:31)
 Copyright (c) 1997-2004 The PHP Group
 Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
 
 // End //
 
 I'm doing something wrong? Or this is the expected behavior? I know
 I could use php references, but linking style does confuse me a bit (
 how do you change a reference to point to a new variable if it's
 allready referencing another one ? )
 
 Thank you in advance
 

Looks right to me. I guess PHP doesn't support it. You may want to
file a bug or look for more on superglobals in the manual or bug
reports.

-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

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



Re: [PHP] Variable Variables adn Superglobals

2004-08-04 Thread ARico
Justin Patrin wrote:
On Wed, 04 Aug 2004 23:15:03 +0200, ARico [EMAIL PROTECTED] wrote:
 

   Using Variable Variables works fine inside functions for global
defined variables if you declare them as global inside the function.
Suprinsingly, it does not seem to work with superglobals. Take the
following example:
// code 
?php
$glob_var=Var 1;
$var_glob_var=glob_var;
$var_ENV=_ENV;
echo $_ENV[OS],\n;
echo $glob_var,\n\n;
echo $var_glob_var,\n;
echo $var_ENV,\n\n;
echo $$var_glob_var,\n;
echo ${$var_ENV}[OS],\n\n;
foo1($var_glob_var);
foo2($var_glob_var);
foo3();
foo4();
foo5($var_ENV);
foo6($var_ENV);
foo7();
foo8();
foo9();
function foo1($arg){
   echo --- In foo1 --\n;
   echo $arg,\n;
   echo $$arg,\n;
   echo --\n;
}
function foo2($arg){
   global $glob_var;
   echo --- In foo2 --\n;
   echo $arg,\n;
   echo $$arg,\n;
   echo --\n;
}
function foo3(){
   $arg=glob_var;
   echo --- In foo3 --\n;
   echo $arg,\n;
   echo $$arg,\n;
   echo --\n;
}
function foo4(){
   global $glob_var;
   $arg=glob_var;
   echo --- In foo4 --\n;
   echo $arg,\n;
   echo $$arg,\n;
   echo --\n;
}
function foo5($arg){
   echo --- In foo5 --\n;
   echo $arg,\n;
   echo ${$arg}[OS],\n;
   echo --\n;
}
function foo6($arg){
   global $_ENV;
   echo --- In foo6 --\n;
   echo $arg,\n;
   echo ${$arg}[OS],\n;
   echo --\n;
}
function foo7(){
   $arg=_ENV;
   echo --- In foo7 --\n;
   echo $arg,\n;
   echo ${$arg}[OS],\n;
   echo --\n;
}
function foo8(){
   global $_ENV;
   $arg=_ENV;
   echo --- In foo8 --\n;
   echo $arg,\n;
   echo ${$arg}[OS],\n;
   echo --\n;
}
function foo9(){
   echo --- In foo9 --\n;
   echo $_ENV[OS],\n;
   echo --\n;
}
?
// Output /
Windows_NT
Var 1
glob_var
_ENV
Var 1
Windows_NT
--- In foo1 --
glob_var
--
--- In foo2 --
glob_var
Var 1
--
--- In foo3 --
glob_var
--
--- In foo4 --
glob_var
Var 1
--
--- In foo5 --
_ENV
--
--- In foo6 --
_ENV
--
--- In foo7 --
_ENV
--
--- In foo8 --
_ENV
--
--- In foo9 --
Windows_NT
--
// Version //
PHP 4.3.7 (cgi-fcgi) (built: Jun  2 2004 15:49:31)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
// End //
   I'm doing something wrong? Or this is the expected behavior? I know
I could use php references, but linking style does confuse me a bit (
how do you change a reference to point to a new variable if it's
allready referencing another one ? )
Thank you in advance
   

Looks right to me. I guess PHP doesn't support it. You may want to
file a bug or look for more on superglobals in the manual or bug
reports.
 

   Thanks, I guess I'll use references. Perhaps posting to internals?


Re: [PHP] Variable Variables adn Superglobals

2004-08-04 Thread Curt Zirzow
* Thus wrote ARico:
Using Variable Variables works fine inside functions for global 
 defined variables if you declare them as global inside the function. 
 Suprinsingly, it does not seem to work with superglobals. Take the 
 following example:
 
 // code 
 ...
 // End //
 
I'm doing something wrong? Or this is the expected behavior? I know 
 I could use php references, but linking style does confuse me a bit ( 
 how do you change a reference to point to a new variable if it's 
 allready referencing another one ? )

This is expected behaviour and is noted in the manual as well:

 http://php.net/variables.predefined

manual
Variable variables:  Superglobals cannot be used as variable
variables  inside functions or class methods.
/manual



Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

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



Re: [PHP] Variable variables

2003-12-23 Thread John W. Holmes
Richard Baskett wrote:
Ok I am trying to create a variable from the value of a variable plus some
extra text tagged on the end of it.
So for example:

$test = '_over';
$$CONFIG['island'].$test = 'testing';
${$CONFIG['island'].$test} = 'testing';

echo hawaii = $hawaii_over;
Why not just use an array for all of this? Almost every time variable 
variables are used, it's a workaround to just using arrays. I don't know 
why these even exist, honestly...

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Variable variables

2003-12-23 Thread Richard Baskett
on 12/23/03 11:04, John W. Holmes at [EMAIL PROTECTED] wrote:

 Richard Baskett wrote:
 Ok I am trying to create a variable from the value of a variable plus some
 extra text tagged on the end of it.
 
 So for example:
 
 $test = '_over';
 $$CONFIG['island'].$test = 'testing';
 
 ${$CONFIG['island'].$test} = 'testing';
 
 echo hawaii = $hawaii_over;
 
 Why not just use an array for all of this? Almost every time variable
 variables are used, it's a workaround to just using arrays. I don't know
 why these even exist, honestly...

I might not be sure what you mean, about using an array for all of that, but
within one line of code, it is taking care of a variable that will change
depending on the config island variable. Otherwise I would have needed to
use a switch statement, which is a whole lot more than just one variable.
But then again if your array solution would work in one line.. then I would
love to see it!

Cheers!

Rick

It is the mark of an educated mind to be able to entertain a thought
without accepting it. - Aristotle

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



RE: [PHP] Variable variables question?

2003-06-16 Thread Ford, Mike [LSS]
 -Original Message-
 From: Douglas Douglas [mailto:[EMAIL PROTECTED]
 Sent: 14 June 2003 00:57
 
 Thanks for the explanation, but I think this is a
 different case, isn't? I'm not trying to do this
 ${$_POST}, I'm trying to make this string $_POST.

Then why not just make it: 

   $var = '$_'.$method;

(Forgive me if I've misunderstood and that's not what you mean!)


 And I have another question. Why does this code work?
 
 ?php
 echo 'pre';
 print_r($_POST);
 echo '/prebrbr';
 $method = 'POST';
 $data = ${'_'.$method};
 echo 'pre';
 print_r($data);
 echo '/prebrbr';
 ?

H'mm, interesting -- that does seem to be in contradiction of the Warning I pointed 
out before.  You're definitely using the variable variables trick to access a 
superglobal!  Sorry, I'm stumped on this one... ;(

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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



RE: [PHP] Variable variables question?

2003-06-13 Thread Ford, Mike [LSS]
-Original Message-
From: Douglas Douglas
To: [EMAIL PROTECTED]

To get the superglobal array ($_GET or $_POST), I try
to build these strings '_'.$method. I'm sure this part
works, PHP builds the string _GET or _POST according
to the $method parameter.
I use ${'_'.$method} to get the contents of the
superglobal. But this piece of code doesn't work.

--

Well, it won't, because there's a prominent warning on the manual page 
(http://www.php.net/language.variables.variable) that says:

  Please note that variable variables cannot be used with PHP's
  Superglobal arrays. This means you cannot do things like ${$_GET}.

Cheers!
  

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



RE: [PHP] Variable variables question?

2003-06-13 Thread Douglas Douglas
Thanks for the answer Mike.

Thanks for the explanation, but I think this is a
different case, isn't? I'm not trying to do this
${$_POST}, I'm trying to make this string $_POST.

And I have another question. Why does this code work?

?php
echo 'pre';
print_r($_POST);
echo '/prebrbr';
$method = 'POST';
$data = ${'_'.$method};
echo 'pre';
print_r($data);
echo '/prebrbr';
?

It does what I want it to do. I use it as the action
of the same form I submitted before and it does print
the superglobal array twice. The difference between
this code and the one that doesn't work is that the
latter is a class method.

What do you think? Thanks again.

__
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

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



Re: [PHP] Variable Variables

2002-09-13 Thread Marek Kilimajer

Hi,

Mike Smith wrote:

I am stumped on a project for a receiving system. I'm not sure how to handle
receiving more than one line item. I can UPDATE ... WHERE id=$detid when I
have 1 item, but how would I get the SQL to fire X times depending on the
number of line items I have AND UPDATE the appropriate record.

Currently I have the following:

index.php-results.php-recv.php
Search for |Results of PO|Page to receive/back order
PO  ($ponum|Search  |items.
or $vendor)

The code below displays the line items from the PO:

...
$myServer = myserver;
$myUser = login;
$myPass = password;
$myDB = db;

$s = mssql_connect($myServer, $myUser, $myPass)
or die(Couldn't connect to SQL Server on $myServer);

$d = mssql_select_db($myDB, $s)
or die(Couldn't open database $myDB);

$sql=SELECT tbl_po.poid, tbl_po.vend_name, tbl_podet.qty,
tbl_podet.unitqty, tbl_podet.um, tbl_podet.partnum, tbl_podet.partdesc FROM
tbl_po INNER JOIN tbl_podet ON tbl_po.poid = tbl_podet.ponum WHERE
(((tbl_po.poid)=$ponum));

$result = mssql_query($sql);
$numRows = mssql_num_rows($result);
...
[HTML Table header]
...
while($row = mssql_fetch_array($result)) {

echo tr align=center valign=top;
echo td align=center . $row[0] . /td;
echo td align=center . $row[1] . /td;
echo td align=center . $row[2] . /td;
echo td align=center . $row[3] . /td;
echo td align=center . $row[4] . /td;
echo td align=left . $row[5] . /td;
echo td align=left . $row[6] . /td;
echo td align=centerinput type=\text\ name=\recvd\/td;
echo td align=centerinput type=\text\ name=\bkord\/td;

the last two lines should look like this

echo td align=centerinput type=\text\ name=\recvd[$row[id]]\/td;

echo td align=centerinput type=\text\ name=\bkord[$row[id]]\/td;

then you'll get arrays $recvd and $bkord with ids as their keys, which you can loop 
trought

echo /tr;
echo /font;
echo /form;
}
echo /table;
echo input type=\submit\ name=\Receive\ value=\Receive\;

The last 2 boxes in the table are for Recvd qty and Back Order Qty. The
problem is I could have 1 line item or I could have 10 line items. So if I
have 1 item and my SQL is UPDATE tbl_podetail SET bkorder=$bkord WHERE
id=$detid that will work fine, but if I have 10 items, the same UPDATE
statement will only update the LAST $detid, it won't fire 10 times for item.
I could add another column with a button next to each line item to save the
changes, but would (for simplicity) rather have the one Receive button.


Regards,
Mike Smith



  



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





Re: [PHP] variable variables i think... (solved)

2002-08-22 Thread Justin French

Solved it -- I *can* do what I wanted without variable variables... it was
human error.

Justin French


on 22/08/02 4:09 PM, Justin French ([EMAIL PROTECTED]) wrote:

 Hi all,
 
 Having trouble with the logic behind this.
 
 I have a dynamic SKU, and a dynamic size_range array.
 
 Examples:
 
 $sku = '44044';
 $size_range = array('S', 'M', 'L');
 
 
 Which I use to build a pull down select box:
 
 SELECT name=myselect
 ?
 foreach($sizes as $k = $v)
 {
 echo OPTION value=\$v\$v/OPTION;
 }
 ?
 /SELECT
 
 
 Note, the select's name is just a string now, not an array.  Sinxe there are
 many SKU's on the page, What I'd like to do is dynamically generate this
 name, so that each SKU is part of an array. Eg:
 
 $selected_size['44044'] = 'M';
 $selected_size['44045'] = 'S';
 $selected_size['44046'] = 'L';
 etc etc
 
 This will make processing the data HEAPS easier.
 
 
 So I need to dynamically generate the SELECT's name:
 
 SELECT name=selected_size['?=$sku?']
 
 Easy.
 
 
 BUT, since this form may be spat back out to the user if fields were left
 blank, etc etc, I like to do something like:
 
 SELECT name=myselect
 ?
 foreach($sizes as $k = $v)
 {
 $myselect = $_POST['myselect'];
 if($myselect == $v) { $sel =  selected; } else { $sel = ; }
 echo OPTION value=\{$v}\{$sel}{$v}/OPTION;
 }
 ?
 /SELECT
 
 Which ensures that any values they did select will still be selected when
 they get given the form again to make changes.
 
 Trouble is, with a dynamically assigned SELECT name, I have no idea how to
 test for an existing value.
 
 I thought it'd be something like:
 
 SELECT name=myselect['?=$sku?']
 ?
 foreach($sizes as $k = $v)
 {
 $myselect[$sku] = $_POST['myselect'][$sku];
 if($myselect[$sku] == $v) { $sel =  selected; } else { $sel = ; }
 echo OPTION value=\{$v}\{$sel}{$v}/OPTION;
 }
 ?
 /SELECT
 
 But this isn't working.  My guess is that I need variable variables, or some
 other way of referencing the select's name.
 
 Any ideas welcome.
 
 
 
 Justin French
 


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




Re: [PHP] Variable Variables

2002-05-30 Thread Ed Gorski

use isset($$key);

ed

At 09:29 AM 5/30/2002 +1000, David Freeman wrote:
Hi All,

I've been trying to figure this out based on stuff on php.net but can't
seem to get a result I need.

I have an array:

$formarray = array (form1 = var1, form2 = var2);

And now I'm using that array to create a form (fairly abbreviated):

while (list($key, $val) = each($formarray))
{
   echo $val:;
   echo input name=\$key\
}

What I'm looking to do is set a value in my input tag if a value has
been set.  That is, if this form has been submitted then the variable
$form1 will contain a value (well, $POST[$form1] will but you get the
idea).

I want to test if $form1 has a value and if it does then I can add a
value= arg in my input tag.

I've got as far as working out that $$key will give me the equivalent of
$form1 but how do I then work out if $form1 has a value?

CYA, Dave



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


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




RE: [PHP] Variable Variables

2002-05-29 Thread David Freeman


  I've got as far as working out that $$key will give me the 
  equivalent of $form1 but how do I then work out if $form1 
  has a value?

Never mind, ${$key} was what I was looking for - my test case set the
wrong variable and that's why it didn't seem to be working.

CYA, Dave


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




RE: [PHP] Variable Variables

2002-05-29 Thread Philip Olson

 Never mind, ${$key} was what I was looking for - my test case set the
 wrong variable and that's why it didn't seem to be working.

You may want to code with E_NOTICE errors showing.  To 
show all levels, use error_reporting:

  error_reporting(E_ALL);

This will show you undefined variables, and then some.
Note that error_reporting is both a function (runtime) 
and a php directive.

Most PHP users feel that developing with E_ALL is good.

Regards,
Philip Olson

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


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




RE: [PHP] Variable Variables

2002-05-29 Thread David Freeman


  You may want to code with E_NOTICE errors showing.  To 
  show all levels, use error_reporting:
  
error_reporting(E_ALL);

Yeah, I already do that...

CYA, Dave



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




RE: [PHP] variable variables

2002-01-17 Thread scott [gts]

there's one example of var-of-vars along with arrays below my rant

rant
var-of-var is almost always an evil thing.  there are some
rare instances where they're necessary, but i assure you
that your script would be MUCH cleaner and easier to modify
in the future if you used a simple array.

compare: $value = $form[$temp . $i];
to: eval('$valueofsize = $'. $temp . $i .';');
/rant

$form['size1'] = hey;
$form['size2'] = there;

$size1 = hey;
$size2 = there;
$loopcounter = 2;

while ($i++  $loopcounter) {
$temp = size;
eval('$valueofsize = $'. $temp . $i .';');
print $valueofsize;
print $form[$temp . $i];
}


Scott Hurring - Internet Programmer
GraphicType Services
tel: 973.667.9486
web: http://www.graphictype.com/
pgp: http://graphictype.com/scott/pgp.txt



 -Original Message-
 From: Mike Krisher [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, January 17, 2002 11:12 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] variable variables


 I can not wrap my head around variable variables today, not awake yet or
 something.

 For instance I trying something like this:

 while ($i$loopcounter) {
   $temp = size;
   $valueofsize = $$temp$i;
   $i++;
 }

 this doesn't work obviously, $valueofsize ends up with a literal value of
 $size1. But I need it to equal the value of a variable named $size1. Do I
 need to use a eval() or something?

 Thanks in advance,
 » Michael Krisher
   [EMAIL PROTECTED]


 --
 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]





-- 
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]




Re: [PHP] variable variables

2002-01-17 Thread Steve Cayford


On Thursday, January 17, 2002, at 10:11  AM, Mike Krisher wrote:

 I can not wrap my head around variable variables today, not awake yet or
 something.

 For instance I trying something like this:

 while ($i$loopcounter) {
   $temp = size;
   $valueofsize = $$temp$i;

try $valueofsize = ${$temp$i};

   $i++;
 }

 this doesn't work obviously, $valueofsize ends up with a literal value 
 of
 $size1. But I need it to equal the value of a variable named $size1. 
 Do I
 need to use a eval() or something?

 Thanks in advance,
 » Michael Krisher
   [EMAIL PROTECTED]


 --
 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]



--
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]




Re: [PHP] variable variables

2002-01-17 Thread [EMAIL PROTECTED]


$valueofsize = ${size . $i};

or

$var = size . $i;
$valueofsize = $$var;

bvr.

On Thu, 17 Jan 2002 11:11:43 -0500, Mike Krisher wrote:

I can not wrap my head around variable variables today, not awake yet or
something.

For instance I trying something like this:

while ($i$loopcounter) {
   $temp = size;
   $valueofsize = $$temp$i;
   $i++;
}

this doesn't work obviously, $valueofsize ends up with a literal value of
$size1. But I need it to equal the value of a variable named $size1. Do I
need to use a eval() or something?

Thanks in advance,
¯ Michael Krisher
  [EMAIL PROTECTED]


--
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]






--
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]




Re: [PHP] variable variables

2002-01-17 Thread Alister

On Thu, 17 Jan 2002 11:11:43 -0500, you wrote:

I can not wrap my head around variable variables today, not awake yet or
something.

For instance I trying something like this:

while ($i$loopcounter) {
   $temp = size;
   $valueofsize = $$temp$i;
   $i++;
}

What about

$i = 0; // set the start (or use for())
while ($i$loopcounter) {
   $temp = size. $i; // $temp = 'size1', 'size2'...
$valueofsize = $$temp;
$i++;   # untested code, should be OK though
} 

No messing around with evals neccessary.

Alister

-- 
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]




Re: [PHP] Variable variables

2001-09-26 Thread Philip Olson


If I'm reading your snippet correctly, then :

  $foo = 'bar';
  $bar = array('apple','banana');

  print ${$foo}[0]; // apple

Note the use of {braces}.  The last paragraph in the manual describes this
a bit :

  http://www.php.net/manual/en/language.variables.variable.php

Although I don't see the point of $newvar as you're keeping track of $a in
the array itself.  Looks like the below code will create a ton of
variables (arrays) each with one $a as the single key.  Just using
$finalresult may be more appropriate, hard to say.

And some tips :

  $arr[foo] will create an error/warning here, $arr['foo'] will not.
  $foo isn't as pretty as $foo

regards,
Philip Olson


On Wed, 26 Sep 2001, Richard Baskett wrote:

 I can not figure out why this is not working!
 
 for ($j=0; $j$resultNum; $j++) {
   $newvar = finalresult.$a;
   $$newvar[$a][name] = $resultRow[name];
   $$newvar[$a][title]= $resultRow[title];
   $$newvar[$a][descript] = $resultRow[descript];
   $$newvar[$a][countkey] = substr_count($resultRow[keywords], $keyword);
   a++;
 }
 
 This is how you use variable variables, is it not?  Is it because it's a
 multidimensional array?  or am I missing something else?
 
 Rick
 
 
 -- 
 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]
 




-- 
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]




Re: [PHP] Variable variables

2001-03-13 Thread Jason Stechschulte

On Tue, Mar 13, 2001 at 06:36:10AM -0700, John Meyer wrote:
 Okay, I read about this feature in the php manual.  What I can't figure out
 is why in the world would anybody want to use this feature?  Not to start a
 flame war, just would like an explanation of why this feature is useful.

I've really only used them once, but they were handy for that situation.
I had a column in a mysql table that was a set column of user
privileges, and I wanted to register every value in the set as a session
variable.  

horridcode
for($i = 0; $i  sizeof($privs); $i++) {
   $$privs[$i] = 1;
   session_register($privs[$i]);
}
/horridcode


-- 
Jason Stechschulte
[EMAIL PROTECTED]
--
I surely do hope that's a syntax error.
 -- Larry Wall in [EMAIL PROTECTED]

-- 
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]




RE: [PHP] Variable variables

2001-03-13 Thread John Meyer

Okay, that makes a little sense, but isn't there some sort of collection
that will do the same thing (coming from vb).

-Original Message-
From: Jason Stechschulte [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 13, 2001 6:38 AM
To: John Meyer
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Variable variables


On Tue, Mar 13, 2001 at 06:36:10AM -0700, John Meyer wrote:
 Okay, I read about this feature in the php manual.  What I can't figure
out
 is why in the world would anybody want to use this feature?  Not to start
a
 flame war, just would like an explanation of why this feature is useful.

I've really only used them once, but they were handy for that situation.
I had a column in a mysql table that was a set column of user
privileges, and I wanted to register every value in the set as a session
variable.

horridcode
for($i = 0; $i  sizeof($privs); $i++) {
   $$privs[$i] = 1;
   session_register($privs[$i]);
}
/horridcode


--
Jason Stechschulte
[EMAIL PROTECTED]
--
I surely do hope that's a syntax error.
 -- Larry Wall in [EMAIL PROTECTED]


-- 
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]




RE: [PHP] Variable variables

2001-03-13 Thread PHPBeginner.com

Hey, there are also arrays,

these can do much more and can be used most of the times you think of
var-var solution...


Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com




-Original Message-
From: John Meyer [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 13, 2001 10:47 PM
To: Jason Stechschulte
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP] Variable variables


Okay, that makes a little sense, but isn't there some sort of collection
that will do the same thing (coming from vb).

-Original Message-
From: Jason Stechschulte [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 13, 2001 6:38 AM
To: John Meyer
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Variable variables


On Tue, Mar 13, 2001 at 06:36:10AM -0700, John Meyer wrote:
 Okay, I read about this feature in the php manual.  What I can't figure
out
 is why in the world would anybody want to use this feature?  Not to start
a
 flame war, just would like an explanation of why this feature is useful.

I've really only used them once, but they were handy for that situation.
I had a column in a mysql table that was a set column of user
privileges, and I wanted to register every value in the set as a session
variable.

horridcode
for($i = 0; $i  sizeof($privs); $i++) {
   $$privs[$i] = 1;
   session_register($privs[$i]);
}
/horridcode


--
Jason Stechschulte
[EMAIL PROTECTED]
--
I surely do hope that's a syntax error.
 -- Larry Wall in [EMAIL PROTECTED]


--
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]



-- 
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]