#34937 [Fbk->Opn]: Fatal error when passing object's return-value as parameter by reference
ID: 34937
User updated by: fredrik at demomusic dot nu
Reported By: fredrik at demomusic dot nu
-Status: Feedback
+Status: Open
Bug Type: *Programming Data Structures
Operating System: Linux
PHP Version: 5.0.5
New Comment:
Problem exists in 5.0.6-dev, Build time Oct 21 2005 10:16:08
Previous Comments:
------------------------------------------------------------------------
[2005-10-21 08:57:42] derick@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.0-win32-latest.zip
------------------------------------------------------------------------
[2005-10-21 04:22:32] fredrik at demomusic dot nu
Description:
------------
A bug most likely connected with the fixed bug #31525:
PHP-Changelog 5.0.5: -Fixed bug #31525 (object reference being dropped.
$this getting lost). (Stas, Dmitry)
(http://bugs.php.net/bug.php?id=31525)
When passing an object's return-value as parameter by reference I get a
fatal error for code that worked flawlessly in 5.0.4.
Reproduce code:
---------------
I am using the Smarty-framework. This function is from Smarty.php and
is the one involved in the error:
/**
* assigns values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param mixed $value the referenced value to assign
*/
function assign_by_ref($tpl_var, &$value)
{
if ($tpl_var != '')
$this->_tpl_vars[$tpl_var] = &$value; //Lineno 603
}
Code:
$smarty->assign_by_ref ('soldStatus', $object->getSoldStatus ());
//Lineno 341
For clarity, this is the getSoldStatus()-method:
/**
* Get the sold-status of this ad.
* @return int The sold-status of this ad.
*/
public function getSoldStatus () {
return (int) $this->soldStatus;
}
And for yet more clarity, from the top of getSoldStatus's class:
/**
* @var int This' sold-status. 0 for not sold. 1 for sold.
*/
protected $soldStatus;
Expected result:
----------------
Is in PHP 4.0.4 Win32 and Linux, I suspect the "assign_by_ref"-method
to be executed, and, I guess, after bug-fix #31525, I would expect an
E_STRICT error in Smarty.php on line 603 later on.
Conclusivly, as I do not have E_STRICT error_reporting on, I would
expect my code to work as it did in php 5.0.4!
Actual result:
--------------
Fatal error: Only variables can be passed by reference in
/my/path/guiFunctions.php on line 341
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34937&edit=1
Thread (9 messages)