php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24745 return ($val) is broken for references
Submitted: 2003-07-21 19:48 UTC Modified: 2003-07-22 02:25 UTC
From: vma1 at abv dot bg Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2003-07-21 (dev) OS: Slackware Linux 9.0
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: vma1 at abv dot bg
New email:
PHP Version: OS:

 

 [2003-07-21 19:48 UTC] vma1 at abv dot bg
Description:
------------
"return ($val);" does not work in a function that returns a reference. "return $val;" is OK.

Reproduce code:
---------------
class lala
{
	var $val;
	
	function lala ()
	{
		$this->val = 0;
	}
	
	function &get_val ()
	{
		$inf = 88;
		$this->val = $inf;
		return ($inf);
	}
}

$obj = new lala;
$vvv = &$obj->get_val ();


Actual result:
--------------
Fatal error: Only variables or references can be returned by reference in /usr/local/apache/site/htdocs/bug.php on line 15

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-22 02:25 UTC] derick@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

Yup, this is expected.
 [2003-08-08 07:56 UTC] no dot spam at forme dot pt
http://pt.php.net/return

statement: "Note:  Note that since return() (...), the parentheses surrounding its arguments are not required (...) it doesn't matter one way or the other."

in example above, return ($val) or return $val seems to matter.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Dec 02 14:00:01 2025 UTC