property_exists()

property_exists()

I've been using isset() or count() or any number of other functions to determine if a variable exists or not. It's unreliable and drives me mad with errors in my code "property of a non object"

For example when you're deciding on the flow of your code based on a property of an object you can use this function.

			
				

stdClass Object
(
    [test] => MULTIPLE_LIABILITIES
    [http_code] => 200
    [headers] => stdClass Object
        (
            [Content-Type] => Array
                (
                    [0] => application/json
                )
        )
)


//is $data->test avalable to the code


if(property_exists($data, 'test')){

    //do something

} else {

   //do something else

}

So much easier to use ;-)