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



[PHP] Variable variables and references

2007-03-10 Thread Dave Goodchild

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