php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31245 Assigning reference to self results in &$GLOBALS
Submitted: 2004-12-22 15:39 UTC Modified: 2005-03-17 09:20 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rhm31 at cam dot ac dot uk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.9 OS: FreeBSD
Private report: No CVE-ID: None
 [2004-12-22 15:39 UTC] rhm31 at cam dot ac dot uk
Description:
------------
Assigning an global object to be a reference of itself causes the object to point to $GLOBALS, but only when read from $GLOBALS.

This shows up as the *RECURSION* in the acutal result below.
Note also that Win32 works fine but FreeBSD gives this problem.

Reproduce code:
---------------
<?php

class A
{
}

$obj=&new A;

function &GetA()
{
	global $obj;
	return $obj;
}

$obj=&new A;
$obj=&GetA();

echo("<PRE>");
var_dump($obj);
print_r($GLOBALS);
echo("</PRE>");
?>

Expected result:
----------------
object(a)(0) {
}
Array
(
...
    [GLOBALS] => Array
 *RECURSION*
    [obj] => a Object
        (
        )

)

//Note this result is obtained in PHP 4.3.9 on Win32

Actual result:
--------------
object(a)(0) {
}
Array
(
...
    [GLOBALS] => Array
 *RECURSION*
    [obj] => Array
 *RECURSION*
)
//Note this result is obtained in PHP 4.3.9 on FreeBSD

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-22 15:41 UTC] rhm31 at cam dot ac dot uk
In the example code, the first $obj=&new A; is not needed, sorry.
 [2005-03-17 09:20 UTC] sniper@php.net
Yeah, don't do that. You can crash PHP with other infinite recursive things too. This won't change.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 18:01:28 2024 UTC