473,288 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Accessing stdClass object vars

Hi,

I have the following object, I need to extract the SysMessage
property.

stdClass Object ( [UnknownConsignment] =stdClass Object
( [SysMessage] =Your consignment could not be found on our
system ) )

I could do this:
$object->UnknownConsignment->SysMessage

However, depending on the condition, the "UnknownConsignment" property
might be called something else.
Therefore, I need a solution, something like an array:
$object->[0]->SysMessage

Thanks in advance!

Mar 1 '07 #1
5 53840
get_object_vars will actually give you an array of properties an object have

Hendri

JamesG wrote:
Hi,

I have the following object, I need to extract the SysMessage
property.

stdClass Object ( [UnknownConsignment] =stdClass Object
( [SysMessage] =Your consignment could not be found on our
system ) )

I could do this:
$object->UnknownConsignment->SysMessage

However, depending on the condition, the "UnknownConsignment" property
might be called something else.
Therefore, I need a solution, something like an array:
$object->[0]->SysMessage

Thanks in advance!
Mar 1 '07 #2
On Mar 1, 1:58 am, Hendri Kurniawan <ask...@email.comwrote:
get_object_vars will actually give you an array of properties an object have

Hendri

JamesG wrote:
Hi,
I have the following object, I need to extract the SysMessage
property.
stdClass Object ( [UnknownConsignment] =stdClass Object
( [SysMessage] =Your consignment could not be found on our
system ) )
I could do this:
$object->UnknownConsignment->SysMessage
However, depending on the condition, the "UnknownConsignment" property
might be called something else.
Therefore, I need a solution, something like an array:
$object->[0]->SysMessage
Thanks in advance!

Thanks for the tip.
I'm trying to use this, but it's not working how I like.

The array is now as follows:
Array ( [UnknownConsignment] =stdClass Object ( [SysMessage] =Your
consignment could not be found on our system ) )

So you would assume by using: $array[0] would access the object, and:
$array[0]->SysMessage contains the message I want.
This does not work! I know it's something silly, so any further help
is appreciated!

Thanks again

Mar 1 '07 #3
JamesG wrote:
On Mar 1, 1:58 am, Hendri Kurniawan <ask...@email.comwrote:
>get_object_vars will actually give you an array of properties an object have

Hendri

JamesG wrote:
>>Hi,
I have the following object, I need to extract the SysMessage
property.
stdClass Object ( [UnknownConsignment] =stdClass Object
( [SysMessage] =Your consignment could not be found on our
system ) )
I could do this:
$object->UnknownConsignment->SysMessage
However, depending on the condition, the "UnknownConsignment" property
might be called something else.
Therefore, I need a solution, something like an array:
$object->[0]->SysMessage
Thanks in advance!


Thanks for the tip.
I'm trying to use this, but it's not working how I like.

The array is now as follows:
Array ( [UnknownConsignment] =stdClass Object ( [SysMessage] =Your
consignment could not be found on our system ) )

So you would assume by using: $array[0] would access the object, and:
$array[0]->SysMessage contains the message I want.
This does not work! I know it's something silly, so any further help
is appreciated!

Thanks again
Hi James,

It doesn't work because it returns associated array.
What you have to do is get the name of that keys using array_keys.

$variables = get_object_vars($object);
$keys = array_keys($variables);
print $variables[$key[0]]->SysMessage;

Hendri Kurniawan
Mar 1 '07 #4
On Mar 1, 3:37 am, Hendri Kurniawan <ask...@email.comwrote:
JamesG wrote:
On Mar 1, 1:58 am, Hendri Kurniawan <ask...@email.comwrote:
get_object_vars will actually give you an array of properties an object have
Hendri
JamesG wrote:
Hi,
I have the following object, I need to extract the SysMessage
property.
stdClass Object ( [UnknownConsignment] =stdClass Object
( [SysMessage] =Your consignment could not be found on our
system ) )
I could do this:
$object->UnknownConsignment->SysMessage
However, depending on the condition, the "UnknownConsignment" property
might be called something else.
Therefore, I need a solution, something like an array:
$object->[0]->SysMessage
Thanks in advance!
Thanks for the tip.
I'm trying to use this, but it's not working how I like.
The array is now as follows:
Array ( [UnknownConsignment] =stdClass Object ( [SysMessage] =Your
consignment could not be found on our system ) )
So you would assume by using: $array[0] would access the object, and:
$array[0]->SysMessage contains the message I want.
This does not work! I know it's something silly, so any further help
is appreciated!
Thanks again

Hi James,

It doesn't work because it returns associated array.
What you have to do is get the name of that keys using array_keys.

$variables = get_object_vars($object);
$keys = array_keys($variables);
print $variables[$key[0]]->SysMessage;

Hendri Kurniawan
Thanks Hendri, works perfectly.

Mar 1 '07 #5
My pleasure
Mar 1 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: red | last post by:
If I use PEAR to produce an accociative array from a mysql table, and display the array with print_r, it says it is an array and it displays values like a regular array: Array ( => 1 =>...
2
by: juglesh | last post by:
hello, i have a d/l'd class that gives an array which prints like this: stdClass Object ( ] => stdClass Object ( => text => => fisrt name => yes
4
by: Skrol29 | last post by:
Hello, It can be very usefull to code: $obj = new stdClass; Unfortunately the few that the documentation officially tells about this class is: ****************************** The name stdClass...
3
by: Jorgen Bodde | last post by:
Hi all, I wanted to solve a small problem, and I have a function that is typically meant only as a function belonging inside another function. function like; def A(): some_var = 1 def B():...
2
by: Jean Marie | last post by:
Hi, i have a problem with the usage of stdClass. From a SOAP based web service i get a code list as an array of stdClass instances: array ( 0 => stdClass::__set_state(array(
9
ebcovert3
by: ebcovert3 | last post by:
Ok, I really need help. I am running EE (an older version admittedly) but this just started happening. I noticed a lot of spam accounts being requesting authorization to my website. I went in to the...
1
by: electronik | last post by:
Hello! My var_export() from $object says: stdClass::__set_state(array( 'event_id' => '21', 'test' => 5, 'anode' => NULL, )) I want to access 'anode'.
6
by: muckymuck | last post by:
Hello, i would like to know how i can get better output from a foreach. this code: $x = $wpdb->get_results("SELECT * FROM " . WP_PLAATJES); foreach ($x as $y) { print_r($y); var_dump( $y...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.