php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44565 constructor argument by reference return value
Submitted: 2008-03-29 16:42 UTC Modified: 2008-03-31 12:13 UTC
From: wursttrooper at gmx dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
 [2008-03-29 16:42 UTC] wursttrooper at gmx dot de
Description:
------------
When using a func return value by reference as constructor argument, produces 
Fatal error: Can't use method return value in write context in D:\xampplite\htdocs\test\writectx.php on line 22

removing by ref '&' symbol lets code execute.

Reproduce code:
---------------
<?
class MyClass {
	function func1() {
			return "ret func1";		
	}		
}
class MyClass2 {
		function __construct( $str, $obj ) {			
		}
}

$obj= new MyClass();

/******************
Fatal error: Can't use method return value in write context in D:\xampplite\htdocs\test\writectx.php on line 22
******************/
$c2 = new MyClass2("sf",&$obj->func1());

/******************
works
******************/
$c2 = new MyClass2("sf",$obj->func1());
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-29 19:41 UTC] felipe@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

See:
- http://docs.php.net/manual/en/language.references.pass.php
 [2008-03-31 12:13 UTC] wursttrooper at gmx dot de
alright I see that was not correctly coded by myself. 

But the error message was missleading. I just could not make any sense out of the "write context". I would have expected the deprecation warning as I knew it from before, when things were passed by reference at the call.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 23:01:25 2019 UTC