php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50872 inaccurate example in pass-by-reference docs
Submitted: 2010-01-28 10:19 UTC Modified: 2010-01-29 09:01 UTC
From: neilyalowitz at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2010-01-28 10:19 UTC] neilyalowitz at gmail dot com
Description:
------------
There must be a mistake in the documentation regarding the "Produces fatal error" documented case.  Docs need to be fixed, it doesn't produce a fatal error, the code block runs fine.

Reproduce code:
---------------
---
From manual page: language.references.pass
---

<?php
function bar() // Note the missing &
{
    $a = 5;
    return $a;
}

//begin-- I added this so the block will run
function foo($a) {
        print $a;
}
//end

foo(bar()); // Produces fatal error since PHP 5.0.5  //no, it doesn't

?>


Expected result:
----------------
Docs say it should produce a fatal error.

Actual result:
--------------
Code block runs fine.  No error.

Mistake in the docs.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-28 10:21 UTC] neilyalowitz at gmail dot com
URL to page I'm referring to:

http://www.php.net/manual/en/language.references.pass.php
 [2010-01-28 12:56 UTC] salathe@php.net
Please see the function foo() as defined at the top of the page. At least two people have been confused by that example so it will probably make sense to tidy the page up a bit.
 [2010-01-28 21:00 UTC] neilyalowitz at gmail dot com
Ok, now I understand.

I would recommend just pasting function foo() as defined above in the example given further down the page.  Then the code block could be run as-is, readers could observe the error themselves, and there is no ambiguity:


<?php
function foo(&$var)
{
    $var++;
}

function bar() // Note the missing &
{
    $a = 5;
    return $a;
}
foo(bar()); // Produces fatal error since PHP 5.0.5

foo($a = 5); // Expression, not variable
foo(5); // Produces fatal error
?>
 [2010-01-29 08:57 UTC] svn@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&revision=294184
Log: Added function foo to make references examples standalone. Fixes #50872
 [2010-01-29 09:01 UTC] salathe@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.

I have added the function foo() to the two snippets which did not have it. Thanks again for your input. 
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 06:00:01 2026 UTC