Access object property via array - php

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.

Related

MTURK API: Accessing Private Field of Assignment Object from PHP?

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();

PHP object variable not assignable but exist

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..

A complex soap call using PHP

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>
';

PHP / NetSuite - nsComplexObject Doesn't Exist

I am not certain if I am maybe misunderstanding, something in the examples I see, but any time I try to make sure of nsComplexObject, I get an error that it does not exist.
I am specifically trying to create a sales order. I set up my array of values, but when I try to do the following, I get an error:
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$salesOrder = new nsComplexObject('SalesOrder');
?>
I think you're looking at older Toolkit examples.
The newer versions (I think since 2012_2) use a different method for instantiating objects, such as:
$salesOrder = new SalesOrder();
You can still use the setFields method to populate object properties, but you can also populate them directly now:
$salesOrder->entity = $someRecordRefObject;

To understand a line of PHP code about a connection

What is connection() in the following code?
Code which I do understand completely
if($user->connection($email,$password)){
}
Let's assume connection() is pseudo-code.
Is the pg_prepare and pg_execute` enough to create the connection?
The line caused me to omit the use of its main code in generating a login system. Subsequently, SOers pointed out severe sequrity holes in my code.
I could not find the explanation for the function connection().
The code seems to be pseudo-code to me, since the connection does not have any attributes to the database, for instance by
Example of how the connection should be formed
$result = pg_prepare($dbconn, "query22", "SELECT passhash_md5 FROM users
WHERE email=$1;");
$passhash_md5 = pg_execute($dbconn, "query22", array($_REQUEST['email']));
$user is an instance of a class.
connection is a method in that class.
$mail & $password are parameters to that method.
This has nothing todo with arrays. what you mean would be:
$foo = array("key" => "value");
maybe this can help you:
http://www.webstockbox.com/php/7-tutorials-on-how-to-create-a-php-login-system/
I haven't actually used php.net, but this just looks like connection is a method of object $user that takes 2 params. Nothing to do with arrays.

Categories