PHP/SOAP 未捕获的 SoapFault 异常:调用未定义的方法
我正在尝试让一个非常小的 SOAP 系统正常工作,但是我在一个(小)问题上苦苦挣扎了几天,而 Google 也无法帮助我......
我想做的:我想做一些关于我在类中传递的一些变量的事情。 问题:我想将 server.php 文件中的传入类用作对象。但这是不可能的。
我的服务器 PHP 文件:
class Lid
{
public $NumberOfYears; //this one is public for example purpose only
private $tew;
private $School;
private $Price;
public function __construct($dump){
$this->tew = "dump:".$dump;
}
public function getPrice(){
return $this->Price;
}
}
class Functies{
public function __construct(Lid $Lid){
$Lid->getPrice(); //What I want to do
return new Lid($Lid->NumberOfYears);
}
}
$classmap = array('Lid'=>'Lid');
$server = new SoapServer(NULL,
array(
'classmap'=>$classmap,
'uri' => "http://127.0.0.1/ns/soap/")
);
$server->setClass("Functies");
$server->handle();
“Functies”类包含我想通过 SOAP 导出的所有方法。我使用传输类 Lid 作为参数。我真正想做的是调用传入类 $Lid 上的方法。 当我尝试运行客户端脚本时,它返回以下错误: 未捕获的 SoapFault 异常:[SOAP-ENV:Server] 调用未定义的方法 stdClass::getPrice()
我理解这个问题。 PHP 认为参数 $Lid 是一个类,而不是一个对象。
所以,我的问题是:
- 如何使 $Lid 成为一个对象?
- 如何访问我的私有/公共变量?我尝试通过 $Lid->NumberOfYears 来执行此操作,但这只是返回一个空字符串。
提前致谢
I'm trying to make a very small SOAP system working, but I'm struggling with a (small) problem for a few days and Google couldn't help me neither...
What I want to do: I want to do some things on a few variables, which I'm passing in a class.
Problem: I want to use the incoming class on my server.php file as an Object. But that's not possible.
My server PHP file:
class Lid
{
public $NumberOfYears; //this one is public for example purpose only
private $tew;
private $School;
private $Price;
public function __construct($dump){
$this->tew = "dump:".$dump;
}
public function getPrice(){
return $this->Price;
}
}
class Functies{
public function __construct(Lid $Lid){
$Lid->getPrice(); //What I want to do
return new Lid($Lid->NumberOfYears);
}
}
$classmap = array('Lid'=>'Lid');
$server = new SoapServer(NULL,
array(
'classmap'=>$classmap,
'uri' => "http://127.0.0.1/ns/soap/")
);
$server->setClass("Functies");
$server->handle();
The class "Functies" has all the methods I want to export via SOAP. I'm using the transport class Lid as an Argument. What I actually want to do is calling methods on the incoming class $Lid.
When I try to run the client script, it is returning the following error:Uncaught SoapFault exception: [SOAP-ENV:Server] Call to undefined method stdClass::getPrice()
I understand the problem. PHP thinks that the argument $Lid is a class, and not an object.
So, my questions:
- How can I make $Lid an object?
- How can I access my private / public variables? I tried to do this via
$Lid->NumberOfYears
but that's just returning an empty string.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大约两年前,我尝试做一些非常接近您在这里尝试的事情。
从那时起,我就尽可能少地使用 SOAP。
事实上,对于非常简单的数据结构(如果我记得很好的话,关联数组是我能够毫无问题地使用的“最好的”数组)。
一旦我想在客户端和服务器之间“共享”带有方法、高级属性等的完整类,就根本不可能达到我的目标(例如,无法在传输的对象上执行方法)。
因此,在花费太多时间和头痛之前,我放弃了这个想法,并使得通过 SOAP 传输仅具有简单结构的数据成为可能......
HTH。
About two years ago, I've tried to do something really close to what you are attempting here.
Since those days, I use SOAP as less as possible.
In fact, SOAP works quite well (I say "quite" because of the obscure, redundant and verbose WSDL definition, and for the awful, unclear error messages of the PHP SOAP library), for very simple data structures (associative arrays being the "best" I've been able to use without problem if I remember well).
As soon as I wanted to "share" a full class with methods, advanced properties etc. between a client and server, it was simply impossible to reach my goal (e.g. unable to execute a method on a transferred object).
So I gave up that idea before taking too much time and headache on it, and made all that was possible to transfer data having only simple structures through SOAP...
HTH.
又等了几天等待更多回复后我就放弃了。
我的解决方案:如果 PHP 没有为我创建一个对象,我就自己创建它。
因此,我没有导出“Functies”类,而是创建了一个额外的类(functiesNew),具有相同的方法,但使用普通变量作为输入(如上面的人所说,使用简单的数据结构)。
After waiting a few more days waiting for more replies I just gave up.
My solution: if PHP isn't making an object for me, I will make it on my own.
So instead of exporting the class "Functies" I just created an extra class (functiesNew), with the same methods, but with normal variables as input (using simple data structures as the person above was saying).