如何给php中的类成员赋值

时间:2014-01-03 22:41:04

标签: c# php

我在php中有一个方法,我需要调用它并向它发送一些变量。这是我调用方法的地方:

$param = array (
'AuthenticationKey' => $authkey,
'vconfig' => ?,
'vcondition' =>$vcondition,
'ZipCode' =>$ZipCode,
'VersionDate' => $currentdate,
);


$result = $client->call('GetVehicleValuesByVehicleConfiguration', array('parameters' => $param), '', '', false, true);  

我发送给此方法的变量之一是类('vconfig' => ?)这一个。 我不确定如何初始化该类及其成员,并将其作为参数发送到此方法。

我用它来初始化类:

  $vconfig = new  $client.VehicleConfiguration;

但另一种方法是给我一些我需要传递给这个类的值,我不知道如何。我已经使代码在C#中工作,但不知道如何在PHP中使用它。这就是我在C#中谈论的内容。

   ServiceReference1.VehicleConfiguration vconfig = new ServiceReference1.VehicleConfiguration();


  var getValue2 = soapClient.GetVehicleConfigurationByVehicleId(AuthenticationId, ap, 2, "01602", current);


          //dont know how to do this part in php
         vconfig.Year = getValue2.Year;
         vconfig.Make = getValue2.Make;
         vconfig.Model = getValue2.Model;
         vconfig.Trim = getValue2.Trim;
         vconfig.Mileage = getValue2.Mileage;
         vconfig.OptionalEquipment = getValue2.OptionalEquipment;

我不知道如何在php中执行最后一部分vconfig.Year = getValue2.Year; 这是我需要为元素赋值的Web服务类代码:

   public partial class VehicleConfiguration : object,    System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {

    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

    private int IdField;

    private string VINField;

    private ConsumeKbbAPI.ServiceReference1.IdStringPair YearField;

    private ConsumeKbbAPI.ServiceReference1.IdStringPair MakeField;

    private ConsumeKbbAPI.ServiceReference1.IdStringPair ModelField;

    private ConsumeKbbAPI.ServiceReference1.IdStringPair TrimField;
    //private ConsumeKbbAPI.ServiceReference1.VehicleTrim TrimField;



    private int MileageField;

1 个答案:

答案 0 :(得分:1)

这取决于您的Configuration类,但如果您在C#中拥有公共成员,则可以使用:

<?php

//Example of class
class Configuration {
  public $year;
  public $model;
  //and so on
}

//Example of instantiation
$vconfig = new Configuration();

//Here's the syntax you're looking for
$vconfig->year = 2002;
$vconfig->model = "Something";