php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25951 Error suppression operator + reference return statement => corrupt func. params
Submitted: 2003-10-22 09:43 UTC Modified: 2003-10-23 22:29 UTC
From: dand at codemonkey dot ro Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.3 OS: Debian Linux 3.0
Private report: No CVE-ID: None
 [2003-10-22 09:43 UTC] dand at codemonkey dot ro
Description:
------------
The code + results should be pretty self explainatory.

A workaround would be to remove either the reference operator "& getElement" or the error suppression operator "@$this->hash".

PS: I know that using @ instead of isset() is wrong, especially in this situation...

Reproduce code:
---------------
class Foo {
	var $hash;

	function  & getElement($name) {
		return @$this->hash[$name];
	}	

	function bar($a, $b, $c, $d)
	{
		print "BAR: $a, $b, $c, $d<br>";
	}	
}

$f = new Foo();

for ($k = 0; $k < 3; $k++) {
	$t = $f->getElement($k);
	$f->bar(1, 2, 3, 4);
}

Expected result:
----------------
BAR: 1, 2, 3
BAR: 1, 2, 3
BAR: 1, 2, 3

Actual result:
--------------
BAR: 1, 2, 3
BAR: 3, 3, 3
BAR: 3, 3, 3

[If it helps, in PHP 4.1.2 the actual result is:
BAR: 3, 3, 3
BAR: 3, 3, 3
BAR: 3, 3, 3
]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-22 09:46 UTC] dand at codemonkey dot ro
Sorry, the actual code producing the results above is:

class Foo {
	var $hash;

	function  & getElement($name) {
		return @$this->hash[$name];
	}	
	
	function bar($a, $b, $c)
	{
		print "BAR: $a, $b, $c<br>";
	}	
}

$f = new Foo();

for ($k = 0; $k < 3; $k++) {
	$t = $f->getElement($k);
	$f->bar(1, 2, 3);
}
 [2003-10-23 22:29 UTC] iliaa@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 should not return string offsets by reference. In PHP 5.0 this would result in the following warning message:
Fatal error: Only variables or references can be returned by reference
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 01:01:27 2024 UTC