Re: Variable variables and references

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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

only for objects really - and 'most' peoples php4 code misuses objects
in such a way that they don't notice.

in php4 objects travel aruond as copies, in php5 they always move around
as references to the original object created with $foo = new Foo; unless you
specifically use 'clone' on an object variable.

or did I miss something else?

> 
> 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 use objects quite a lot, although as I have progressed I have become
less addicted to them. recently I have been using not so much objects but
mostly abstract classes - as a poormans namespacing device - a neat way of
grouping functions and variables that belong in a single 'domain' (thereby
minimizing global namespace pollution and giving my brain some nice 'containers'
to help organize my thoughts/functionality/stuff.

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

ack to that. I vaguely remember even using variable variable variables
once, something akin to:

$foo = "tada!";
$s_1 = "foo";
$x   = 1;
$s   = "s";

echo ${${"{$s}_{$x}"}}, "\n";

evil has many forms!

> Well, younger and more foolish.

as years go by I get an ever increasing suspicion that youth and foolishness
are inversely proportial :-/

> 

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux