|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-10-18 14:24 UTC] sonya at look-for-it dot de
Description:
------------
I have problem with $GLOBALS while executing scripts via SOAP Service. Objects passed by reference is not set in $GLOBALS and cannot be used in other classes. The same code works perfectly if executed direct in browser.
Reproduce code:
---------------
client.php
----------------------------------------------
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("test.wsdl", array('trace'=> 1, 'exceptions' => 0));
print $client->testGlobals();
--------------------------------------------
server.php
----------------------------------------------
function testGlobals() {
global $TestClass1, $TestClass2;
require_once 'inc.php';
return $TestClass2->testvar2;
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("test.wsdl");
$server->addFunction("testGlobals");
$server->handle();
--------------------------------------------
inc.php
--------------------------------------------
require_once('TestClass1.class.php');
require_once('TestClass2.class.php');
$TestClass2 = new TestClass2();
-------------------------------------------
TestClass1.class.php
-------------------------------------------
class TestClass1 {
public $testvar1;
function TestClass1() {
$this->testvar1 = 100;
}
}
$TestClass1 = & new TestClass1();
---------------------------------------------
TestClass2.class.php
---------------------------------------------
class TestClass2 {
public $testvar2;
function TestClass2() {
global $TestClass1;
$this->testvar2 = $TestClass1->testvar1;
}
}
Expected result:
----------------
I expect the value 100 to be returned by service.
Actual result:
--------------
Nothing is returned. The reason is that in TestClass2 there is no $GLOBALS['TestClass1'] unless I pass $TestClass1 by value:
(last line of TestClass1.class.php):
$TestClass1 = new TestClass1();
What is wrong here?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 11 02:00:01 2025 UTC |
Your expectation is wrong and report is not releated to SOAP at all. It is related to "global" and references. The following script does exactly the same. <?php class TestClass1 { public $testvar1; function TestClass1() { $this->testvar1 = 100; } } class TestClass2 { public $testvar2; function TestClass2() { global $TestClass1; $this->testvar2 = $TestClass1->testvar1; } } function testGlobals() { global $TestClass1, $TestClass2; $TestClass1 =& new TestClass1(); // breaking reference $TestClass2 = new TestClass2(); return $TestClass2->testvar2; } var_dump(testGlobals()); ?> global $TestClass1; - $TestClass1 become a reference to a global variable $TestClass1 =& ... - $TestClass1 become a reference to assigned object (the global variable is not affected by such assignment) Thank you for report anyway.