php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9453 Reference issue
Submitted: 2001-02-26 05:07 UTC Modified: 2001-07-09 08:06 UTC
From: mailling at bigfoot dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: Windows 2000
Private report: No CVE-ID: None
 [2001-02-26 05:07 UTC] mailling at bigfoot dot com
I tried it with: allow_call_time_pass_reference	= Off and allow_call_time_pass_reference	= On

It seems that the result is not send automatically as a reference

class A{

function &b(&$f) {
	$d=&$f;
	$f='5';
	return $d;
}

}

$c='3';
$d=new A();
$h=$d->b($c);
$h=&$d->b($c); //The & is needed to work well
$h='9';
echo $c. ' '.$h;

The value of c is not updated correctly if we don't ask for a reference

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-08 06:38 UTC] stas@php.net
Works for me. What are the results in your case?
 [2001-03-08 14:55 UTC] mailling at bigfoot dot com
let's run this code
<?php
class A{

function &b(&$f) {
        $d=&$f;
        $f='5';
        return $d;
}

}
$c='3';
$d=new A();
$h=$d->b($c);
//$h=&$d->b($c); //The & is needed to work well
//we get $h=&$c;
$h='9';
echo $c. ' '.$h;
//since we should see 9 9, but we can see 5 9
?>

we get 5 9
If we adapt the code to:
//$h=$d->b($c);
$h=&$d->b($c); //The & is needed to work well

we get 9 9, and that should be the good value, rigth?
 [2001-07-09 08:06 UTC] jeroen@php.net
This is expected behaviour. You *need* the $a =& func(),
a mere function &func() definition is not sufficient.

Agreed, this is not really nice... But $a = func() should
always return by value, you don't need to know how func() is
defined.

Equally, $a =& func() shouldn't work when it isn't defined
as returning by reference, since the function might not be
expecting it.

Btw: This has nothing to with call_time_pass_ref

status->bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC