#46885 [Fbk->Opn]: Passing a variable by Reference does not return object created in function
| From: | Chowarmaan at gmail dot com | Date: | Wed, 17 Dec 2008 23:14:39 +0000 |
| Subject: | #46885 [Fbk->Opn]: Passing a variable by Reference does not return object created in function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-132106@lists.php.net to get a copy of this message | ||
ID: 46885
User updated by: Chowarmaan at gmail dot com
Reported By: Chowarmaan at gmail dot com
-Status: Feedback
+Status: Open
Bug Type: Scripting Engine problem
Operating System: Windows 2000/XP
PHP Version: 5.2.8
New Comment:
Both lines were added to show what works and what does not. The first
call is the desired call by the program and what I can see in the PHP
manual. However, $Response does not become an object of TEST_CLASS2
when the GetResponse function ends.
The second call, &$Response does maintain the TEST_CLASS2 object type.
The second line should not be in the script, it is just there to
illustrate the problem. The first call to GetResponse() is the correct
call by the language syntax, but it has the bug.
Previous Comments:
------------------------------------------------------------------------
[2008-12-17 02:44:50] jani@php.net
How about you comment out the latter call and let the script work
like it does?
------------------------------------------------------------------------
[2008-12-16 21:26:23] Chowarmaan at gmail dot com
Description:
------------
Calling a function in a class that accepts a variable by reference,
then checks the variable and creates an object for it will not allow the
object to be returned outside of the function.
Reproduce code:
---------------
<?php
class TEST_CLASS
{
function __construct() { }
function GetResponse(&$Response, $Timeout = 0)
{
if (!($Response instanceof TEST_CLASS2 ))
$Response = new TEST_CLASS2();
$Response->SetText_('Testing Complete');
return TRUE;
}
}
class TEST_CLASS2
{
public $Variable;
public function SetText_($s)
{
$this->Variable = $s;
}
}
$Test = new TEST_CLASS();
$Test->GetResponse($Response, 100); // Fails
$Test->GetResponse(&$Response, 100); // Works
echo $Response->Variable . "\n";
?>
Expected result:
----------------
$Response should be of type TEST_CLASS2 and the echo should return the
text:
Testing Complete
Actual result:
--------------
$Response is a NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46885&edit=1