note 94174 added to language.references.pass
| From: | Anonymous at osu1 dot php dot net | Date: | Wed, 21 Oct 2009 00:24:48 +0000 |
| Subject: | note 94174 added to language.references.pass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161927@lists.php.net to get a copy of this message | ||
As stated in the documentation, passing values by reference is not supported by PHP.
<?php
function bar() // Note the missing &
{
$a = 5;
return $a;
}
foo(bar()); // Produces fatal error since PHP 5.0.5
?>
The return value of bar() cannot be passed by reference to foo(&$something). However the
following seems to be valid:
<?php
$test = bar();
foo($test);
?>
You may also encounter problems for calls with fixed values, such as:
<?php
foo(null); // Produces fatal error
foo(5); // Produces fatal error
?>
The following calls (by putting the values in variables) are possible:
<?php
$null = null;
foo($null);
$five = 5;
foo($five);
?>
Is there any reason that passing a fixed value is not supported by PHP? I guess this limitation just
causes avoidable problems.
----
Server IP: 69.147.83.197
Probable Submitter: 87.246.65.122
----
Manual Page -- http://www.php.net/manual/en/language.references.pass.php
Edit -- https://master.php.net/note/edit/94174
Del: integrated -- https://master.php.net/note/delete/94174/integrated
Del: useless -- https://master.php.net/note/delete/94174/useless
Del: bad code -- https://master.php.net/note/delete/94174/bad+code
Del: spam -- https://master.php.net/note/delete/94174/spam
Del: non-english -- https://master.php.net/note/delete/94174/non-english
Del: in docs -- https://master.php.net/note/delete/94174/in+docs
Del: other reasons-- https://master.php.net/note/delete/94174
Reject -- https://master.php.net/note/reject/94174
Search -- https://master.php.net/manage/user-notes.php