Php check stdclass property exists
I have read some similar issues here but unfortunately find the solution for my case. Show Some part of the output for an API connection is as;
Some strings do not include gpps property. What I have done is as follows
What I want is I the gpps property is not included in that string $subId stored as 0-0 in db, otherwise get the data from the string. But it doesn't get the strings without gpps. Where is my mistake?
asked Dec 4, 2013 at 20:51
6 Change
with
notice how now
answered Dec 4, 2013 at 21:11
Matteo TassinariMatteo Tassinari 17.6k7 gold badges60 silver badges80 bronze badges property_exists is the method designed for this purpose. bool property_exists ( mixed $class , string $property ) answered Dec 4, 2013 at 21:09
JC.JC. 6703 silver badges12 bronze badges Try a simple hack and use count, since the property contains an array, and I guess, that count(array) == 0 is the same case as when the property is not set.
Sure, this is not the most beautiful solution, but since the php-function do not work as expected, I thought a bit more pragmatic. answered Dec 5, 2013 at 11:24
QullbruneQullbrune 1,9252 gold badges20 silver badges20 bronze badges Another way , get_object_vars
answered Dec 13, 2016 at 23:38
Fevly PallarFevly Pallar 3,0192 gold badges14 silver badges19 bronze badges How to check if property exists in PHP?The property_exists() method checks if the object or class has a property.. Syntax. property_exists(object, property). Parameters.. Return. The property_exists() function returns TRUE if the property exists, FALSE if it doesn't exist or NULL in case of an error.. Example. The following is an example −. Output.. How check stdClass object is empty in PHP?Check if count( (array)$yourObject) ) == 0 .
How do you check if a key exists in an object PHP?PHP array_key_exists() Function
The array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.
How do you access the properties of an object in PHP?Within class methods non-static properties may be accessed by using -> (Object Operator): $this->property (where property is the name of the property). Static properties are accessed by using the :: (Double Colon): self::$property .
|