OOP issue
| From: | Christian Schneider | Date: | Mon, 15 Nov 1999 13:54:32 +0000 |
| Subject: | OOP issue | ||
| References: | 1 2 3 4 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-6238@lists.php.net to get a copy of this message | ||
After seeing Andi Gutmans' mail about changing $a['x'] to $a{'x'} to
clean up the language I figured it would make sense to discuss some more
points on how to enhance the language. The downside is that these
changes break existing code but on the other hand PHP4 might be the last
chance to fix things.
I want to propose changing assignment of objects from copy to reference,
i.e. change the semantics of
$a = $some_object; to what's currently done by $a = &$some_object;
and to introduce
$a = clone($some_object); to what's currently done by $a = $some_object.
My limited OOP experience tells me that 95% of the time one wants a
reference, not a copy.
While having the reference operator around is inelegant but working I
ran into severe problems trying to iterate through an associative array
containing objects: each() and friends always return copies of the
contained objects.
The best solution I found was doing something like
for (reset($b); $object = &$b[key($b)]; next($b))
While copying may work most of the time even when a reference would be
more appropriate it adds unnecessary overhead to the program.
Opinions?
- Chris
--
Chris Schneider - mailto:cschneid@relog.ch
Computers are not intelligent. They only think they are.