Answers for "php cannot use object of type stdclass as array in"

PHP
10

cannot use object of type stdclass as array

$obj_user = json_decode($user, true);

use json_decode($obj, true); 	// add true
Posted by: Guest on January-27-2021
0

Cannot use object of type stdClass as array in isset

function deliciousCount($domain_name) {
    $data = json_decode(
        file_get_contents(
            "http://feeds.delicious.com/v2/json/urlinfo/data?url=$domain_name"
        )
    );
    // You should double check everything because this delicious function is broken
    if (is_array($data) && isset($data[ 0 ]) &&
        $data[ 0 ] instanceof stdClass  && isset($data[ 0 ]->total_posts)) {
        return $data[ 0 ]->total_posts;
    } else {
        return 0;
    }
}
Posted by: Guest on February-16-2022

Code answers related to "php cannot use object of type stdclass as array in"

Browse Popular Code Answers by Language