|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29423 reference count gets wrong when return-reference-calling a normal function
Submitted: 2004-07-28 10:59 UTC Modified: 2005-06-07 11:58 UTC
Avg. Score:5.0 ± 0.0
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:3 (50.0%)
From: stefan at hotpaenz dot de Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS, 4CVS OS: Linux 2.6.3
Private report: No CVE-ID: None
 [2004-07-28 10:59 UTC] stefan at hotpaenz dot de
See the code below: 
An object of ClassA is passed to FuncB, which calls FuncA 
with the return-by-reference operator. FuncA is not 
designed to return by reference. 
The reference count seems to get wrong by doing that so 
the object is discarded when FuncB returns. 

Reproduce code:
class ClassA { }

function FuncA($obj) {
    return $obj;

function FuncB($obj) {
    $dummy = &FuncA($obj);

$obj = new ClassA();
$str='This is a string'

Expected result:
object(ClassA)#1 (0) { } 

Actual result:
string(16) "This is a string" 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-06 22:12 UTC]
Please try using this CVS snapshot:
For Windows:

 [2005-03-07 11:50 UTC] stefan at hotpaenz dot de
The bug remains for me with "latest cvs" snapshot 
200503070930, configured with 
./configure --disable-cli --enable-cgi --without-pear 
 [2005-03-07 12:13 UTC] stefan at hotpaenz dot de
Of course you could make this code cause an fatal error 
(instead of the "expected result" that PHP4 returns), but 
please please please don't let it fail silently. It easily 
leads to errors that are really hard to track.
 [2005-03-07 12:49 UTC]
Confirmed here too (with PHP 4) and it leaks too:

string(16) "This is a string"
/dat/dev/php/php-5.0dev/Zend/zend_execute.c(253) :  Freeing 0x085E7994 (16 bytes), script=-
=== Total 1 memory leaks detected ===

assigning to Dmitry
 [2005-06-07 11:58 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 17:01:30 2024 UTC