ID:               25975
 Updated by:       [EMAIL PROTECTED]
 Reported By:      reiersol at online dot no
-Status:           Open
+Status:           Bogus
 Bug Type:         Session related
 Operating System: Linux RedHat 9.0
 PHP Version:      5CVS-2003-10-24 (dev)
 New Comment:

Still can't see what might be wrong here. 
The result you get is pretty much what I would expect to get..



Previous Comments:
------------------------------------------------------------------------

[2003-10-31 03:42:04] reiersol at online dot no

I guess I'll have to expand my example:

class Bar { var $value = 0; }
class Foo {
    var $v1;
    var $v2;
    function Foo() {
        $this->v1 = new Bar;
        $this->v2 = $this->v1;
    }
}

$f = new Foo;
$f->v2->value = 42;
var_dump($f);
$g = unserialize(serialize($f));
$g->v2->value = 'and now for something completely different';
var_dump($g);

Here's the output:

object(foo)#1 (2) {
  ["v1"]=>
  object(bar)#2 (1) {
    ["value"]=>
    int(42)
  }
  ["v2"]=>
  object(bar)#2 (1) {
    ["value"]=>
    int(42)
  }
}
object(foo)#3 (2) {
  ["v1"]=>
  object(bar)#4 (1) {
    ["value"]=>
    int(42)
  }
  ["v2"]=>
  object(bar)#5 (1) {
    ["value"]=>
    string(42) "and now for something completely different"
  }
}

That should at least make it clear that there's a difference in
behavior before and after serialization. And the behavior before
serialization is the behavior of a normal object-oriented language. (I
ported the example to Java just to make sure I wasn't crazy.)

I'm not trying to split hairs. I tried creating the kind of
sophiticated object-oriented structure that PHP 5 makes so much easier.
It worked wonderfully. But then I discovered that the structure didn't
persist across sessions. So I made this simplified example to
demonstrate the problem.

------------------------------------------------------------------------

[2003-10-30 20:59:30] [EMAIL PROTECTED]

There are no references in the before serialize object, so why should
there be references after serializing/unserializing?


------------------------------------------------------------------------

[2003-10-24 08:11:44] reiersol at online dot no

The last line of the code example (print $1) is meaningless. Sorry.

------------------------------------------------------------------------

[2003-10-24 08:08:59] reiersol at online dot no

Description:
------------
Object references inside PHP5 objects are not preserved through
serialize/unserialize like traditional PHP4 references. This means they
cannot be used in session-based applications.

Reproduce code:
---------------
class Bar {}
class Foo {
    var $v1;
    var $v2;
    function Foo() {
        $this->v1 = new Bar;
        $this->v2 = $this->v1;
    }
}

$f = new Foo;
var_dump($f);
$g = unserialize(serialize($f));
var_dump($g);
print $s1;


Expected result:
----------------
This is what I get if I use $this->v2 = &this->$v1 instead of $this->v2
= $this->v1:

object(foo)#1 (2) {
  ["v1"]=>
  &object(bar)#2 (0) {
  }
  ["v2"]=>
  &object(bar)#2 (0) {
  }
}
object(foo)#3 (2) {
  ["v1"]=>
  &object(bar)#4 (0) {
  }
  ["v2"]=>
  &object(bar)#4 (0) {
  }
}

Actual result:
--------------
object(foo)#1 (2) {
  ["v1"]=>
  object(bar)#2 (0) {
  }
  ["v2"]=>
  object(bar)#2 (0) {
  }
}
object(foo)#3 (2) {
  ["v1"]=>
  object(bar)#4 (0) {
  }
  ["v2"]=>
  object(bar)#5 (0) {
  }
}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25975&edit=1

Reply via email to