Questions tagged [stdclass]

`stdClass` is php's generic empty class, kind of like Object in Java or object in Python.But not actually used as universal base class. Useful for anonymous objects, dynamic properties. It is used when casting other types to objects.

stdClass is php's generic empty class, kind of like Object in Java or object in Python.But not actually used as universal base class. Useful for anonymous objects, dynamic properties. It is used when casting other types to objects.

503 questions
20
votes
7 answers

How to access stdclass object after a specific key value pair?

I have a stdclass object as shown below: stdClass Object ( [text] => Parent [values] => Array ( [0] => stdClass Object ( [id] => /m/0c02911 [text] => Laurence…
Rio
  • 14,182
  • 21
  • 67
  • 107
20
votes
4 answers

Add properties to stdClass object from another object

I would like to be able to do the following: $obj = new stdClass; $obj->status = "success"; $obj2 = new stdClass; $obj2->message = "OK"; How can I extend $obj so that it contains the properties of $obj2, eg: $obj->status //"success" $obj->message…
Florin
  • 2,891
  • 4
  • 19
  • 26
16
votes
5 answers

stdClass object and foreach loops

I am using the following code to get data from a website using Soap. $client = new SoapClient('http://some.url.here'); class SMSParam { public $CellNumber; public $AccountKey; public $MessageCount; public $MessageBody; public…
jason_m
  • 169
  • 1
  • 1
  • 5
15
votes
5 answers

PHP Array stdClass Object - Echo Value

so I have this array saved in a variable title $arr. I want to grab or echo the value of [slug] Array ( [0] => stdClass Object ( [term_id] => 11 [name] => Community Service [slug]…
user982853
  • 2,470
  • 14
  • 55
  • 82
14
votes
2 answers

PHP StdClass - access fields as ->field or ->{'field'}

I'm working on this PHP code collaboration and it seems that some people access PHP StdClass fields like this $body->head and others like $body->{'head'} As far as I can tell these are equivalent. Are they? Does it matter which is used? Which…
PapaFreud
  • 3,636
  • 4
  • 34
  • 45
13
votes
4 answers

How to access a member of an stdClass in PHP that starts with an @

I have some json object that I decoded, and one of the attributes starts with an "@" and I can't access the element with php because it throws an error. [offers] => stdClass Object ( …
Nikhil
  • 485
  • 1
  • 4
  • 16
12
votes
3 answers

PHP JSON decode - stdClass

I was having a question about making a 2D JSON string Now I would like to know why I can't access the following: $json_str = '{"urls":["http://example.com/001.jpg","http://example.com/003.jpg","http://example.com/002.jpg"],"alts":["testing int chars…
FFish
  • 10,964
  • 34
  • 95
  • 136
12
votes
1 answer

Access property in stdClass Object

stdClass Object ( [ModuleAccountInfo] => Array ( [0] => stdClass Object ( [ServerName] => EAST [HostingModule] => ActiveDirectory [ActiveDirectorySiteName] => EAST …
Grug
  • 1,870
  • 5
  • 25
  • 38
11
votes
6 answers

Convert stdClass object to associative array in php

I need to convert this array Array ( [0] => stdClass Object ( [title] => primo ) [1] => stdClass Object ( [title] => secondo )) to Array ( [primo] => primo [secondo] => secondo ) Tried different options, including typecast, …
Ponzio Pilato
  • 315
  • 1
  • 5
  • 18
10
votes
1 answer

stdClass vs array. Which is recommended?

Where is recommended to use one of them? I want to store data from articles listed from db. It's a simple question: echo $Datastore->name; //I like it works with foreach //vs echo $Datastore['name']; Which is the best? Is there any difference…
MM PP
  • 4,050
  • 9
  • 35
  • 61
9
votes
3 answers

How to print properties of stdClass object in PHP?

I have an array that contains standard class object. How can I return the properties (print them out) in a stdClass object?
user973917
7
votes
1 answer

php convert stdClass object to array

Could anyone shed any light as to why I can get this working. I want to query an array to see if the USER->id that is currently logged in is assigned a specific role: $contextroles = get_records_sql("SELECT userid FROM {$CFG->prefix}role_assignments…
Codded
  • 1,256
  • 14
  • 42
  • 74
7
votes
1 answer

PHP: How to parse a stdClass Object?

I'm trying to parse this data that is returned from SmartyStreets (it's an address verification company). Here is an example: Array ( [0] => stdClass Object ( [input_index] => 0 [candidate_index] => 0 …
Edward
  • 9,430
  • 19
  • 48
  • 71
7
votes
3 answers

Trying to clone a stdClass

I'm trying to clone a stdClass object that have an attribut which is a DateTime. But it fails. It looks like the clone is not working. Should I wrote my own __clone() method? What is wrong here? The code: $object = new stdClass; $object->date =…
Spir
  • 1,709
  • 1
  • 16
  • 27
7
votes
3 answers

Why can't I call property_exists on stdClass?

Here is my code: madeUpProperty = "abc"; echo $madeUpObject->madeUpProperty; echo "
"; if (property_exists('stdClass', 'madeUpProperty')) { echo "exists"; } else { echo "does not…
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
1
2
3
33 34