#43412 [Opn->Bgs]: Globals are not set if object passed by reference

From: Date: Mon, 26 Nov 2007 14:53:47 +0000
Subject: #43412 [Opn->Bgs]: Globals are not set if object passed by reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120093@lists.php.net to get a copy of this message
ID: 43412 User updated by: sonya at look-for-it dot de Reported By: sonya at look-for-it dot de -Status: Open +Status: Bogus Bug Type: SOAP related Operating System: Windows XP PHP Version: 5.2.5 New Comment: $GLOBALS are not set because requre_once is called within a function. Sorry, you can close this "bug" :) Previous Comments: ------------------------------------------------------------------------ [2007-11-26 13:03:06] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43412&edit=1

« previous php.bugs (#120093) next »