|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-07-11 13:06 UTC] Jason at hybd dot net
Description:
------------
This bug is a rehash of 33516, but I can't reopen as I'm not the original author.
It seems like you can not pass tempories to function / method parameters.
<?php
class Foo {
public static function bar() {
return array('a' => '1234567890');
}
}
$tmp = Foo::bar();
$var = array_pop($tmp);
?>
Seems to work, but it shouldn't be down to the PHP user (imho) to implement this as this change in PHP 5.1 breaks a lot of existing code.
Reproduce code:
---------------
<?php
class Foo {
public static function bar() {
return array('a' => '1234567890');
}
}
$var = array_pop(Foo::bar());
?>
Expected result:
----------------
$var = '1234567890';
Foo::bar() gets placed in temporary variable
Actual result:
--------------
Fatal error: Only variables can be passed by reference
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 22:00:01 2025 UTC |
This sort of thing needs to throw an error in any version of PHP I think: function foo() { return "blah"; } function bar(&$arg) { $arg = 1; } bar(foo()); While this should work: function & foo() { static $a; return $a; } function bar(&$arg) { $arg = 1; } bar(foo()); And it does in PHP5.1 at least. The first case indicates a clear bug in the code that we really should be catching. I suppose we could compromise and throw a warning in PHP4 and then fall back to passing the argument by value, but that is changing the actual workings of the script and is likely going to be wrong. I think this needs to be part of the reference fixes in PHP4.4. Sucks that it wasn't caught before the 4.4.0 release, but that's the way it goes.