|
Posted by Alan Pinstein on 12/08/05 04:29
[ man.. I just realized that "reply" to this list doesn't send to the
list... replies being re-sent... thanks for the help! ]
On Dec 6, 2005, at 10:45 PM, Curt Zirzow wrote:
> I'm going to jump to the code as fast as possible to explain what I
> can, the key thing to remember in php5 is that the old &$var
> declaration has no real meaning in objects. php5's objects exist
> outside of the old oop reference. Consider:
>
> class Object {
> public $val;
> function __construct($v) {
> $this->val = $v;
> }
> }
>
> In PHP5:
>
> $o = new Object(2);
> $b = $o;
> $b->val = 3;
> print $o->val; // echos 3
>
> in PHP4 (assuming var is used instead of public)
>
> $o = new Object(2);
> $b = $o;
> $b->val = 3;
> print $o->val; // echos 2
>
> This is cause objects in php5 exist all on there own, that get
> referenced to a php variable.
>
>
> On Tue, Dec 06, 2005 at 05:23:45PM -0500, Alan Pinstein wrote:
>>
>> Question #1: Is the fact that references to objects in the form
>> $objRef = &$obj don't bump the refcount of $obj an intended behavior
>> that can be counted on? If so, cool!
>>
>> So, now that we have a way to do weak references, we should be able
>> to implement a reasonable memory management scheme for parent-child
>> objects.
>>
>> Normally from the client side the interface should look something
>> like:
>>
>> $parent = new Parent();
>> $child = new Child();
>> $parent->addChild($child);
>
> Ok, i get to the code and well what I mentioned above explains why
> there is no
> need to use the $o = &$object;
>
> If I take your code and run it against one of the latest version's
> of php 5.1 i will get a var_dump($child) of:
>
> object(pChild)#2 (1) {
> ["parent"]=>
> object(pParent)#1 (1) {
> ["children"]=>
> array(1) {
> [0]=>
> object(pChild)#2 (1) {
> ["parent"]=>
> object(pParent)#1 (1) {
> ["children"]=>
> array(1) {
> [0]=>
> *RECURSION*
> }
> }
> }
> }
> }
> }
>
> Which is what I see as expected results.
>
> Curt.
> --
> cat .signature: No such file or directory
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Navigation:
[Reply to this message]
|