php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43412 Globals are not set if object passed by reference
Submitted: 2007-11-26 13:03 UTC Modified: 2007-11-26 14:53 UTC
From: sonya at look-for-it dot de Assigned:
Status: Not a bug Package: SOAP related
PHP Version: 5.2.5 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sonya at look-for-it dot de
New email:
PHP Version: OS:

 

 [2007-11-26 13:03 UTC] sonya at look-for-it dot de
Description:
------------
I was not able to continue my bug report #43022 because it's set to bogus. But it's still about different behaviour of $GLOBALS within SOAP. I try to make it more clear in this bug report.

Reproduce code:
---------------
Please create a file inc.php

----------------------------
inc.php
----------------------------
class TestClass1 {
	public $testvar1;
	function TestClass1() {
		$this->testvar1 = 100;
	}
}
$TestClass1 = & new TestClass1(); 
// GLOBALS['TestClass1"] is NOT set while executing via SOAP
// GLOBALS['TestClass1"] is set while executing via browser

class TestClass2 {
	public $testvar2;
	function TestClass2() {
		global $TestClass1;
		$this->testvar2 = $TestClass1->testvar1;
	}
}
$TestClass2 = new TestClass2();
----------------------------------------------


then compare $GLOBALS['TestClass1'] while executing in Browser

--------------------------------------
test.php
--------------------------------------
require_once 'inc.php';
print '<pre>';
print_r ($GLOBALS['TestClass1']);
print '</pre>';
--------------------------------------

and while executing via SOAP
--------------------------------------
server.php
--------------------------------------
function testGlobals() {
    global $TestClass1, $TestClass2;
    require_once 'inc.php';
    return serialize($GLOBALS['TestClass1']);
}

--------------------------------------
client.php
--------------------------------------
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("test.wsdl", array('trace'=> 1, exceptions'=> 0));
print '<pre>';
print_r (unserialize($client->testGlobals()));
print '</pre>';
----------------------------------------------

Expected result:
----------------
Expected the same result returned by soap service and displayed in browser. $GLOBALS assignment has to be the same.

Actual result:
--------------
You will find that TestClass1 is assigned to $GLOBALS when executing via Browser and not assigned when executing the _same_ code via SOAP. Unless you pass the object by value in inc.php.

My question is - why there is different behaviour with the same code? Thank you.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-26 14:53 UTC] sonya at look-for-it dot de
$GLOBALS are not set because requre_once is called within a function. Sorry, you can close this "bug" :)
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 23 09:03:33 2021 UTC