My PHP app is accessing MTURK via the API and getting an Assignment object back that looks like this:
I'm trying to access the Answer field. So far I've tried:
$temp = $theResult->Answer;
$temp = $theResult->get('Answer');
...but they throw errors.
What is the correct way to access this field?
This works on my installation:
$answers = $theResult->getAnswer();
Related
I'm facing a problem that I can't answer.
I have an object that I can var_dump and see, with all his variables, but when I try to assign one of his variable I get "Trying to get property of non-object"..
Here's the code (it's from an api):
$teacher = $teachers->loadById($obj->userId); //gives an object teacher
$firstName = $teacher->firstName; // That return the error
If I do a var_dump like this
$teacher = $teachers->loadById($obj->userId);
var_dump($teacher);exit;
$firstName = $teacher->firstName;
I can see that it's an object with an attribute "firstName"
var_dump() result:
Does anyone experienced a situation like this?
I'm using PHP 5.5.12 on a local setup using wamp.
Edit: I noticed something else, this bug only occurs on my local setup. Everything works with my online test setup.. That makes it even more strange..
I've worked on this for about 4 hours and I am real close but just missing the mark – here is what xml needs to look like
<ws:Answer QuestionID="Q_CAM_ID" ws:Datatype="string">
<ws:Value>6838</ws:Value>
</ws:Answer>
Here is what I get
<ns1:Answer QuestionID="Q_CAM_ID">
<ns1:Value>6838</ns1:Value>
</ns1:Answer>
Using
$A1 = new StdClass();
$A1->QuestionID = 'Q_CAM_ID';
$A1->Value =6838;
No matter what I try I can’t get “ws:Datatype="string"” to appear. I believe the answer is the below or real similar
$A1 = new StdClass();
$A1->QuestionID = new StdClass();
$A1->QuestionID->QuestionID ='Q_CAM_ID';
$A1->QuestionID->DataType ='string';
$A1->Value =6838;
But what I keep getting is this error
Catchable fatal error Object of class stdClass could not be converted to string when the soap call is done. If anyone has a clue I would be most appreciative
The simliest way to do it is to use a WSDL to php generator as you'll only deal with PHP object that matches the requires types. Moreover, if you a good WSDL to php generator, you'll have PHP classes that are named as the elements.
You could use https://www.wsdltophp.com or https://github.com/mikaelcom/WsdlToPhp.
Maybe I'm missing something but if you need that XML why not just make it as a String, and then convert it to what you are trying to do? If you are not using a WSDL or SimpleXML, I would just do the following.
$xml =
'
<ws:Answer QuestionID="Q_CAM_ID" ws:Datatype="string">
<ws:Value>6838</ws:Value>
</ws:Answer>
';
How can I simplify this structure:
$properties = $rs->$domains[0];
$dn = $properties[0]->distinguishedname;
Because PHP gives error on such construction:
$dn = $rs->$domains[0][0]->distinguishedname
This should work, or rather none of them should work.
To access a member of a object using the ->operator you don't need to use the $ twice, it should throw an error or warning of some kind as far as i know.
$properties = $rs->$domains[0];
$dn = $properties[0]->distinguishedname;
Should be:
$properties = $rs->domains[0];
$dn = $properties[0]->distinguishedname;
Likewise:
$dn = $rs->$domains[0][0]->distinguishedname;
Should be:
$dn = $rs->domains[0][0]->distinguishedname;
That's the only problem I can see with your code.
Only looking at it quick it seems as though your code should work as long as the data is actually there. Perhaps you try to fetch distinguishedname from a domain that has no properties?
What does the php error say? Do a *var_dump* on your data structure to see that it actually contains the data you expect that it does.
I have a WCF Service, the interfaces work fine when connecting with a c# application but when I connect using a PHP application all variables passed to the service are null.
This is the PHP code used to connect to the service and send the data.
$SelectedFolder = $_REQUEST['folder'];
var_dump($SelectedFolder);
try
{
$client = new SoapClient('http://localhost:8663/Service.svc?wsdl');
$Files = $client->GetAllLatestVersionsString($SelectedFolder);
}
The var dump displays the following
string 'Pictures/Sample/' (length=16)
This is the service code
[OperationContract]
List<VersionedFileDataModel> GetAllLatestVersionsString(string partUri);
I've tried passing a static value instead of a variable and both times the value received by the service is null.
Thanks in Advance for any help,
Matt
Fixed it, I was required to pass the variables through using an array of params, for the example I posted I had to change the code to this.
try
{
$client = new SoapClient('http://localhost:8663/Service.svc?wsdl');
$params->partUri = $SelectedFolder;
$Files = $client->GetAllLatestVersionsString($params);
}
It took me a while to get soap configured in php. Now I'm just trying to learn about it. I'm using the web service here to learn:
http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=19
It says the WSDL is here:
http://www.webservicex.net/stockquote.asmx?wsdl
and this is my code:
$client = new SoapClient('http://www.webservicex.net/stockquote.asmx?wsdl');
$result = $client->getQuote("AAPL");
echo $result;
I'm getting an error saying "Object of class stdClass could not be converted to string". Now I realize that $result is an object, and I'm wondering how do I access data that the server populated? I tried to understand the WSDL but I'm getting nowhere. Is it supposed to be something like:
$result->price
? (That doesn't work by the way...)
Ideas?
When curious about datatypes from the soapserver, use the SoapClient->__getTypes() & SoapClient->__getFunctions() methods
If you return is still not clear, var_dump() your return and examine it.