首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP可捕获致命错误

PHP可捕获致命错误
EN

Stack Overflow用户
提问于 2013-01-26 16:51:29
回答 3查看 1K关注 0票数 0

我正在尝试用wsdl2php在PHP中处理web服务,但做不到。生成的web服务客户端代码,结果为:

代码语言:javascript
复制
class CreateProfile {

  public $firstname;
  public $email;
  public $lastname;
  public $mobile;
  public $password;
  public $provider;
  public $uniqueID;
  public $username;
}

class CreateProfileResponse {

  public $CreateProfileResult;
}

class Profile_WebService extends SoapClient {

  private static $classmap = array(

  'CreateProfile' => 'CreateProfile',
  'CreateProfileResponse' => 'CreateProfileResponse',
);

public function Profile_WebService($wsdl = "http://domain/wcfservice/Profile.WebService.asmx?WSDL", $options = array()) {
foreach(self::$classmap as $key => $value) {
  if(!isset($options['classmap'][$key])) {
    $options['classmap'][$key] = $value;
  }
}
parent::__construct($wsdl, $options);
}


public function CreateProfile(CreateProfile $parameters) {
  return $this->__soapCall('CreateProfile', array($parameters),       array(
          'uri' => 'http://domain/',
          'soapaction' => ''
         )
     );
  }

}

我想这样使用它:

代码语言:javascript
复制
$client = new Profile_WebService();
$client->CreateProfile(array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));

但它一直在说:

代码语言:javascript
复制
PHP Catchable fatal error:  Argument 1 passed to Profile_WebService::CreateProfile() must be an instance of CreateProfile, array given, called.

你能给我讲讲吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-01-26 17:00:12

创建一个新的CreateProfile类实例:

代码语言:javascript
复制
$createProfile = new CreateProfile();

将vars分配给它:

代码语言:javascript
复制
$createProfile->firstname = 'Fred';
$createProfile->email = 'test@example.com';
...
...

然后将该对象传递到您的方法中:

代码语言:javascript
复制
$client = new Profile_WebService();
$client->CreateProfile($createProfile);
票数 0
EN

Stack Overflow用户

发布于 2013-01-26 16:59:25

CreateProfile需要一个对象,而不是数组。所以这就是:

代码语言:javascript
复制
$client = new Profile_WebService();
$client->CreateProfile(array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));

可以快速切换到以下内容:

代码语言:javascript
复制
$client = new Profile_WebService();
$CreateProfile_array = array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062');
$CreateProfile_object = (object)$CreateProfile_array;
$client->CreateProfile($CreateProfile_object);
票数 1
EN

Stack Overflow用户

发布于 2013-01-26 17:03:39

您告诉PHP在CreateProfile类型的函数CreateProfile() 1参数中。

但是在这行$client->CreateProfile(array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));中,您传递的是一个数组类型的变量。

您必须将该数组类型转换为object类型,如下所示:

代码语言:javascript
复制
$client->CreateProfile((object) array('provider' => 'ENERGIZER','username' => 'ENGtest1','password' => '1369','uniqueId' => '102030405062'));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14535353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档