php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40204 "Example 21-3. References with complex arrays" is wrong, and does in fact work
Submitted: 2007-01-23 08:38 UTC Modified: 2007-02-25 18:04 UTC
From: frode at coretrek dot com Assigned: colder (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2 OS: Irrelevant
Private report: No CVE-ID: None
 [2007-01-23 08:38 UTC] frode at coretrek dot com
Description:
------------
Exmaple 21-3 "References with complex arrays" as available on http://www.php.net/manual/en/language.references.whatdo.php is not correct, at least not for PHP version 5.2.0.

The example claims to "not work as expected". But it does work as expected (and contrary to the documented results). Also, even if the example did "not work as expected", there is no explanation for why it is not supposed to work, other than stating that complex arrays "sometimes" (?!?) are copied.

Reproduce code:
---------------
<?php
// taken directly from Example 21-3
$top = array(
   'A' => array(),
   'B' => array(
       'B_b' => array(),
   ),
);

$top['A']['parent'] = &$top;
$top['B']['parent'] = &$top;
$top['B']['B_b']['data'] = 'test';
print_r($top['A']['parent']['B']['B_b']); // array()
?> 

Expected result:
----------------
According to the documentation:

array()



Actual result:
--------------
Array
(
    [data] => test
)
 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-23 09:18 UTC] bjori@php.net
This is complicated issue and _not_ recommended.

The engine still has problem working with complex arrays 
with references to it self and leaks tons of memory while 
doing so.

The example itself works as of 5.1 but still leaks and 
_can_ result in unexpected behavior.
 [2007-02-25 18:04 UTC] colder@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Warning removed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 23:01:28 2024 UTC