Re: [PHP-GENERAL] Can I use Functional Pointer? / Javascript bracelet conflict ?
[email protected] (Dirk Soede)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
> I don't think there will be pointers,
> the language has so far been able to avoid them
> (which is a good think for a scripting language, IMHO).
I would agree to avoiding pointers. But the problem is that PHP copies
objects completely instead of the references to them. This is quite
unpractical. Some examples.
(1) To clean op my code i often make a short-hand for an object further
down in the tree. Say:
$subobj = $this->obj1->obj3...;
Unfortunately this makes a copy, so you will be doing the assignemnts
on the copy.
(2) I want to pass a reference to an object inside an array and give it
to a function. But inside the function you have a (deep) copy of the
original object, even if you pass it by reference.
(3) A parent child relation. You would like to set the child of a parent
object with:
$parent->setChild($child);
It seems as soon as you assign the $child variable inside the method to the
object property an (unnecessary) copy is made.
I find this confusing and unpractical. But i am probably missing out on something.
Please could someone clarify this.
Dirk Soede