|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79367 Undocumented behavior: Pass-by-ref arguments do not have to be initialized
Submitted: 2020-03-11 13:17 UTC Modified: 2020-03-11 13:23 UTC
From: mwolffhh at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
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.
Block user comment
Status: Assign to:
Bug Type:
From: mwolffhh at gmail dot com
New email:
PHP Version: OS:


 [2020-03-11 13:17 UTC] mwolffhh at gmail dot com
From manual page:

Usually, you must define a variable before it is used, otherwise PHP will produce a notice.

When an argument defined as pass-by-reference though, defining the variable before using it is no longer neccessary.

This is not mentioned in the pass-by-ref docs, nor in the function argument docs:

Test script:
function output($s) {
    echo $s;
output($a); // => PHP emits notice, "Undefined variable: a"
$a = "Test";
output($a); // => outputs "Test"

function outputByRef(&$s) {
    echo $s;
outputByRef($a); // => no output, no notice
$a = "Test";
outputByRef($a); // => outputs "Test"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-11 13:23 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-03-11 13:23 UTC]
This is already documented in the section "Assign By

| If you assign, pass, or return an undefined variable by
| reference, it will get created.

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Aug 01 15:01:24 2021 UTC