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
7
votes
1 answer

How to make PHP stdClass Object that has the same name?

I'm working against an API that gives me an stdClass object that looks like this (actual data replaced) "data": [ { "type": "image", "comments": { "data": [ { "created_time": "1346054211", …
Sun_Blood
  • 335
  • 2
  • 5
  • 12
7
votes
4 answers

PHP Array of a stdClass, How to get data?

I would like to print the value of [name]. I am just becoming familiar with standard defined classes and how they are called. Based on this example and logic $arrayobj = new…
sandraqu
  • 1,428
  • 1
  • 14
  • 31
6
votes
2 answers

SOAP Request with tags

This is my first time posting, so forgive me if I'm not very clear. I will also preface this by saying that I really know very little about php and web services. The issue I'm having is this: A SOAP request is generated by an outside source (a…
tehscott
  • 101
  • 8
6
votes
2 answers

PHP stdClass Object, how to get element with the 0 index

I have a stdClass Object like this: print_r($myobj); stdClass Object( [0] => testData ); So it is clear that I cannot get the value by $myobj->0. For getting this value I convert the object to an array, but are there any ways to get without…
sinitram
  • 524
  • 5
  • 14
6
votes
3 answers

When creating my own classes in PHP should I extend stdClass?

While it is not required for a class in PHP to explicitly extend stdClass, I was wondering if there is some kind of best practice or benefit in doing so. Should I extend stdClass when declaring a class? For reference, see What is stdClass in PHP?…
sebataz
  • 1,025
  • 2
  • 11
  • 35
6
votes
3 answers

PHP: how to check if an object's properties have values?

I use this to check if an object has properties, function objectHasProperty($input){ return (is_object($input) && (count(get_object_vars($input)) > 0)) ? true : false; } But then I want to check further to make sure all properties have…
Run
  • 54,938
  • 169
  • 450
  • 748
6
votes
3 answers

How to instantiate stdClass in place

Is it it possible to do this in php? Javascript code: var a = {name: "john", age: 13}; //a.name = "john"; a.age = 13 Instantiate the stdClass variable on the fly ?
Florin
  • 63
  • 1
  • 3
5
votes
3 answers

php appending string to stdClass object

I'm pulling records from database, and I have a filed called content_fr the _fr is being dynamicaly created based on a site language. Getting all records from the table gives me of course content_fr field. What I need to do is manually assign the…
Mike
  • 171
  • 5
  • 10
5
votes
6 answers

PHP strict standards: is this bad?

When I create a standard class I mostly do: $test = null; $test->id = 1; $test->name = 'name'; However in strict-mode I get an error. So obviously the correct way of doing it is: $test = new stdClass(); $test->id = 1; $test->name = 'name'; So I am…
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
5
votes
3 answers

Codeigniter - return my model object instead of stdClass Object

Not sure the best way of phrasing this so bear with me. Within Codeigniter I can return a record set of my object no problem but this is returned as a stdClass object not as an "model" object (for example a Page Object) which I can then use to make…
simnom
  • 2,590
  • 1
  • 24
  • 34
5
votes
3 answers

stdClass Object and array how to using php

I'm trying to get the twelve ids that this structure shows: stdClass Object ( [checkins] => stdClass Object ( [count] => 12 [items] => Array ( [0] => stdClass Object …
user638009
  • 223
  • 1
  • 9
  • 25
5
votes
3 answers

How to loop through array of objects in PHP

I'm very new to PHP and I need your help! I need to write backend for my app that receives json post and write data to json file. And I'm stuck with looping through array. $postData = file_get_contents("php://input"); $request =…
Alexander Vovolka
  • 103
  • 1
  • 1
  • 5
5
votes
4 answers

Casting Eloquent\Collection (Laravel) to stdClass array using Repository pattern

I'm trying to implement the Repository pattern in a Laravel 5 app by following this article. In it, the repository implementation converts the object for the specific data source (in this case Eloquent) to an stdClass so that the app uses a standard…
Vic
  • 2,655
  • 3
  • 18
  • 28
5
votes
2 answers

PHP loop through array of stdClass object

I have a query that I run in MySQL and it returns a result as an stdClass object as following : array(8){ [ 0 ]=>object(stdClass)#36(1){ [ "color" ]=>string(7)"#a0a0a0" }[ 1 ]=>object(stdClass)#35(1){ [ …
user3593154
  • 115
  • 2
  • 9
5
votes
6 answers

stdClass Object problems

I'm struggling to parse the below data using PHP. An API returns it, and I've tried various syntaxes. How do I return the data in a non-object way? Or, what's the syntax to call the data using the stdClass? Could I convert this to one data based…
ader
  • 53
  • 1
  • 1
  • 4
1 2
3
33 34