php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40137 in-function-call variable-define bug
Submitted: 2007-01-15 20:11 UTC Modified: 2007-02-13 11:49 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: kolypto at mail dot ru Assigned: colder (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.0 OS: WinXP
Private report: No CVE-ID: None
 [2007-01-15 20:11 UTC] kolypto at mail dot ru
Description:
------------
I've noticed that the construction doesn't work fine with php 5.1.6 and 5.2.0
php4 is okay with this

The function reciaves value 'IN', prints it, and changes it to 'MOD'... but only in php4 =)
Spent hours catching this

Reproduce code:
---------------
function modify(&$str1)
{
print "\n".'In function:'.$str1;
$str1='MOD';
}

modify($a='IN');
print "\n".$a;

Expected result:
----------------
In function:IN
MOD


Actual result:
--------------
In function:IN
IN

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-15 20:27 UTC] kolypto at mail dot ru
ADD: php 5.2.0 was downloaded from php.net as windows binary
 [2007-01-15 20:36 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2007-01-15 21:28 UTC] kolypto at mail dot ru
I insist.
The parser does not give the expected result in the output.
http://www.php.net/support.php has nothing common with bug reports, this is just a help center
 [2007-01-15 22:23 UTC] kolypto at mail dot ru
Recent research: in 5.0.4 this code works as expected:
 [2007-01-16 03:31 UTC] judas dot iscariote at gmail dot com
sigh. lets see..

function modify(&$str1)
{

print "\n".'In function:'.$str1;
$str1='MOD';

}

// the variable $a is locally **defined** with value "IN"
modify($a='IN'); //this prints 'In function: IN' (as expected)

print "\n".$a; // $a is **already defined** as 'IN', hence it SHOULD print 'IN' **not** MOD

wth are you talking about ?? works as expected.
 [2007-01-16 03:42 UTC] kolypto at mail dot ru
In php4 and php 5.0.4 it is: 
In function:IN
MOD

In php > 5.0.4 it works like you're saying
that's the question =)
 [2007-01-16 08:27 UTC] tony2001@php.net
Turn on error messages and see the error message you're missing:
"Strict Standards: Only variables should be passed by reference"

"$a='IN'" is not a variable, it's an expression and expressions cannot be passed by reference.
No bug here.
 [2007-01-16 21:50 UTC] kolypto at mail dot ru
Okay, i'll note that from 5.0.4 php has silently changed its behavior...
 [2007-02-04 15:21 UTC] kolypto at mail dot ru
Found another thing, in manual:
int socket_select ( array &read, array &write, array &except, int tv_sec [, int tv_usec] )

here's the amps before variables, that's exactly the same as spoken above.

And what we see next, in manual?

$num_changed_sockets = socket_select($read, $write = NULL, $except = NULL, 0);


so, the "bug" i'm complaining above is really strange...
 [2007-02-12 18:55 UTC] tony2001@php.net
Then it should be fixed in the docs.
 [2007-02-13 11:49 UTC] colder@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Also fixed other occurrences of it:
socket_select
stream_select
readline_callback_handler_install
 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=88a0276952a0ed9d35c963368f51478760c2538e
Log: - Fix #40137 ( = NULL pass by ref) - Remove other occurences of it
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 21:01:33 2025 UTC