php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38355 @ operator prevents 'Only variables can be passed by reference' error
Submitted: 2006-08-06 12:52 UTC Modified: 2006-08-06 13:02 UTC
From: dima at snaiper dot no-ip dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.4 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dima at snaiper dot no-ip dot com
New email:
PHP Version: OS:

 

 [2006-08-06 12:52 UTC] dima at snaiper dot no-ip dot com
Description:
------------
@ in argument passed into function prevents 'Fatal error: Only variables can be passed by reference' error.

Reproduce code:
---------------
function test(& $a) {
echo $a;
}
	
$b = "hello";
test($b); // hello
test($b[0]); // 'Fatal error: Only variables can be passed by reference'
test(@ $b[0]); // h

Expected result:
----------------
'Fatal error: Only variables can be passed by reference'

Actual result:
--------------
test(@ $b[0]); // h

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-06 13:02 UTC] helly@php.net
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

You need to use the @ where the error happens. Here it is the passing to the function or in other words the function call and not the access:
php -r \'function test(& $a) {} $b=\"hello\"; @test($b[0]);\'
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 02:00:01 2026 UTC