php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34937 Fatal error when passing object's return-value as parameter by reference
Submitted: 2005-10-21 04:22 UTC Modified: 2005-10-21 17:50 UTC
From: fredrik at demomusic dot nu Assigned:
Status: Closed Package: *Programming Data Structures
PHP Version: 5.0.5 OS: Linux & WinXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fredrik at demomusic dot nu
New email:
PHP Version: OS:

 

 [2005-10-21 04:22 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-21 08:57 UTC] 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 13:17 UTC] fredrik at demomusic dot nu
Problem exists in 5.0.6-dev, Build time Oct 21 2005 10:16:08
 [2005-10-21 14:20 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-10-21 16:37 UTC] tony2001@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

Works fine for me with latest CVS.
 [2005-10-21 17:14 UTC] fredrik at demomusic dot nu
True, now it works. 

I wrote "[21 Oct 1:17pm CEST] fredrik at demomusic dot nu

Problem exists in 5.0.6-dev, Build time Oct 21 2005 10:16:08"

But at the time I did not know that I had to first start (after switching php-folder) _and then restart_ Apache before the page would be updated when pressing f5. I found this out just now when tried the latest snapshot with the reproduce code, which also displays phpinfo().

Could you provide any information of what parts of the source to make a patch from? Where lay this bug? How far from 5.0.6 release do you suspect? In case it is not far I will simply wait till then.
 [2005-10-21 17:36 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

PHP 5.1 with the fix should be available within a month.
 [2005-10-21 17:50 UTC] fredrik at demomusic dot nu
After all that PHP has done for me, putting a few hours of investigating a bug and filing a report is the least we can do. I am very happy with the quick response from your side in handling this matter!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC