ID:               25975
 User updated by:  reiersol at online dot no
 Reported By:      reiersol at online dot no
-Status:           No Feedback
+Status:           Open
 Bug Type:         Zend Engine 2 problem
 Operating System: Linux RedHat 9.0
 PHP Version:      5CVS-2003-10-24 (dev)
 New Comment:

OK. Here is an example using sessions. Exactly the same thing happens.


<?php
class Bar { public $value = 0; }
class Foo {
    public $v1;
    public $v2;
    function Foo() {
        $this->v1 = new Bar;
        $this->v2 = $this->v1;
    }
}
session_start();

if (isset($_SESSION['g'])) {
    //Try these two one at a time to see the different behaviors:
//    $_SESSION['g']->v2 = "I'm no longer an object";
    $_SESSION['g']->v2->value = 42;
} else {
    $_SESSION['g'] = new Foo;
}
?>
<pre>
<?php 
var_dump($_SESSION['g']);
?>
</pre>


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

[2003-12-04 02:22:56] [EMAIL PROTECTED]

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.



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

[2003-11-28 20:40:06] [EMAIL PROTECTED]

Please provide an example script that actually uses sessions,
(it's not the same thing when you do the serialize/unserialize inside
the same script..)



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

[2003-11-10 05:48:59] reiersol at online dot no

Thanks, but I'm afraid this is not quite good enough.

What I'm getting now after serialize/unserialize is:

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

The ampersands occur only after serialization. They indicate that this
is what is known as a reference in PHP 4, which is a symbol table
alias. The objects still don't behave the same before and after. Try
this:

$f->v2 = 'I\'m no longer an object';
$g->v2 = 'I\'m no longer an object';
var_dump($f);
var_dump($g);

As before, $f is the object before serialize/unserialize, $g is the
object after. The output is:

object(foo)#1 (2) {
  ["v1"]=>
  object(bar)#2 (1) {
    ["value"]=>
    int(42)
  }
  ["v2"]=>
  string(23) "I'm no longer an object"
}
object(foo)#3 (2) {
  ["v1"]=>
  &string(23) "I'm no longer an object"
  ["v2"]=>
  &string(23) "I'm no longer an object"
}

As I understand it, in $f we are replacing an object reference with a
string. In $g, we are replacing the value of a variable that's aliased
to another.

You might ask whether this has any practical consequences. I think that
sooner or later it will (in fact, it seems to be happening in my
full-scale example). When it does, it will be very confusing to the
people who encounter the problem. You may get away with this for a
while, but the longer you get away with it the more difficult it might
be to figure out.

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

[2003-11-09 12:34:43] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

This should be fixed in CVS now.


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

[2003-11-04 01:23:53] reiersol at online dot no

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"]=>
    string(42) "and now for something completely different"
  }
  ["v2"]=>
  object(bar)#4 (1) {
    ["value"]=>
    string(42) "and now for something completely different"
  }
}

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/25975

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

Reply via email to