Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get values stdClass Object PHP

Tags:

object

php

I work with mp4 data extract php script. this returns a stdClass Object as below. can anyone tell me how to show the duration from below object. thank you

stdClass Object
(
    [hasVideo] => 1
    [hasAudio] => 1
    [video] => stdClass Object
        (
            [width] => 472
            [height] => 360
            [codec] => 224
            [codecStr] => H.264
        )

    [audio] => stdClass Object
        (
            [codec] => 224
            [codecStr] => AAC
        )

    [duration] => 622.8
)
like image 663
Suneth Kalhara Avatar asked Jun 27 '12 17:06

Suneth Kalhara


People also ask

How do you access the value of a StdClass object?

You create StdClass objects and access methods from them like so: $obj = new StdClass; $obj->foo = "bar"; echo $obj->foo; I recommend subclassing StdClass or creating your own generic class so you can provide your own methods. Thank you for your help!

What is StdClass object in PHP?

The stdClass is the empty class in PHP which is used to cast other types to object. It is similar to Java or Python object. The stdClass is not the base class of the objects. If an object is converted to object, it is not modified.

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 .


1 Answers

You could do:

echo $yourObject->duration;
like image 57
Blaster Avatar answered Sep 25 '22 13:09

Blaster