php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #44467 wrong oop example in provided manual of php installer package
Submitted: 2008-03-18 11:05 UTC Modified: 2008-04-21 12:49 UTC
From: krille at thomaskrille dot de Assigned: rquadling (profile)
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: krille at thomaskrille dot de
New email:
PHP Version: OS:

 

 [2008-03-18 11:05 UTC] krille at thomaskrille dot de
Description:
------------
in the provided (.chm) manual of the php installer package the following example is given in Lang.Ref.->Classes and ...(PHP5)->The Basics:

<?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);
?> 
The above example will output:

NULL
NULL
object(SimpleClass)#1 (1) {
   ["var"]=>
     string(30) "$assigned will have this value"
}

this example describes the php4 behavior, not the php5 one.

i haven't checked if this mistake is also exsists in other provided manuals.

manual version: "Sun Nov 11 00:33:08 2007"

Reproduce code:
---------------
n/a

Expected result:
----------------
n/a

Actual result:
--------------
n/a

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-19 12:51 UTC] rquadling@php.net
Maybe this is a better example.
<?php
class SimpleClass{}

$instance = new SimpleClass();
$assigned   =  $instance;
$reference  =& $instance;

$instance->var = '$assigned will have this value';
var_dump($instance->var);
var_dump($reference->var);
var_dump($assigned->var);

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

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

In PHP5 the output is ...

string(30) "$assigned will have this value"
string(30) "$assigned will have this value"
string(30) "$assigned will have this value"
NULL
NULL
string(30) "$assigned will have this value"


In PHP4 the output is ...

string(30) "$assigned will have this value"
string(30) "$assigned will have this value"
NULL
NULL
NULL
NULL


 [2008-04-21 12:49 UTC] rquadling@php.net
The example is correct.




 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 27 01:01:23 2020 UTC