If the example was ...

[code]
<?php
class SimpleClass
{
   // member declaration
   public $var = 'a default value';

   // method declaration
   public function displayVar() {
       echo $this->var;
   }
}

$instance = new SimpleClass();

$assigned  =  $instance;
$reference  =& $instance;

$instance->var = '$assigned will have this value';

$instance = null; // $instance and $reference become null

var_dump($instance);
var_dump($reference);
var_dump($assigned);
?>
[/code]

Then that would be more meaningfull. The documented example assumes that
you are using the simple class and that you have created an instance of
it. Without that the output is just junk.

E.g.

C:\>php
<?php
class SimpleClass
{
   // member declaration
   public $var = 'a default value';

   // method declaration
   public function displayVar() {
       echo $this->var;
   }
}

$instance = new SimpleClass();

$assigned  =  $instance;
$reference  =& $instance;

$instance->var = '$assigned will have this value';

$instance = null; // $instance and $reference become null

var_dump($instance);
var_dump($reference);
var_dump($assigned);
?>
^Z
NULL
NULL
object(SimpleClass)#1 (1) {
  ["var"]=>
  string(30) "$assigned will have this value"
}

C:\>

-----Original Message-----
From: rejek at sdnet dot pl [mailto:[EMAIL PROTECTED] 
Sent: 02 August 2006 15:21
To: [email protected]
Subject: [PHP-DOC] #38294 [Bgs]: Problem in Example 19-5. Object
Assignment.

 ID:               38294
 User updated by:  rejek at sdnet dot pl
-Summary:          Doc example problem
 Reported By:      rejek at sdnet dot pl
 Status:           Bogus
 Bug Type:         Documentation problem
 Operating System: Linux
 PHP Version:      Irrelevant
 New Comment:

This problem is in Example 19-5. Object Assignment.
The result of code given in documentation is diferent then the shown
one.
So I still think, that is a documentation bug.
Please execude code given in Example 19-5.
As I've written in first message moving line:
$instance->var = '$assigned will have this value'; just after <?PHP tag
make this code giving right anwer.

MR

MR


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

[2006-08-02 13:36:42] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not a bug.
Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report a bug
at http://bugs.php.net/how-to-report.php

Using $instance = null won't affect the object itself. $assigned still
holds a reference to the object, as objects are assigned by reference in
PHP5.

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

[2006-08-02 13:10:28] rejek at sdnet dot pl

In online doc. at:
http://www.php.net/manual/en/language.oop5.basic.php
http://pl.php.net/manual/pl/language.oop5.basic.php
there is the same problem.

MR

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

[2006-08-02 12:22:14] rejek at sdnet dot pl

Description:
------------
Look at the Ex. 19-4 in polish ver. of documentation avaible to download
at http://pl2.php.net/get/php_manual_pl.html.gz/from/pl.php.net/mirror
The line "$instance->var = '$assigned will have this value';"
should be just after "<?PHP" tag to get the expected result given in the
box under ex. code.
I don't know how it looks in other language versions.

Brgs
Mateusz Rejek

Reproduce code:
---------------
<?php
$assigned   =  $instance;
$reference  =& $instance;

$instance->var = '$assigned will have this value';

$instance = null; // $instance and $reference become null

var_dump($instance);
var_dump($reference);
var_dump($assigned);
?>

Expected result:
----------------
NULL NULL object(stdClass)#1 (1) { ["var"]=>  string(30) "$assigned will
have this value" }

Actual result:
--------------
NULL NULL NULL


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


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

Reply via email to