Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Undefined property: stdClass::$items #189

Open
n2ref opened this issue Sep 19, 2023 · 2 comments
Open

Warning: Undefined property: stdClass::$items #189

n2ref opened this issue Sep 19, 2023 · 2 comments

Comments

@n2ref
Copy link

n2ref commented Sep 19, 2023

Warning: Undefined property: stdClass::$items in

/vendor/alaouy/youtube/src/Youtube.php on line 644

Now

    public function decodeSingle(&$apiData)
    {
        $resObj = json_decode($apiData);
        if (isset($resObj->error)) {
            $msg = "Error " . $resObj->error->code . " " . $resObj->error->message;
            if (isset($resObj->error->errors[0])) {
                $msg .= " : " . $resObj->error->errors[0]->reason;
            }

            throw new \Exception($msg);
        } else {
            $itemsArray = $resObj->items;
            if (!is_array($itemsArray) || count($itemsArray) == 0) {
                return false;
            } else {
                return $itemsArray[0];
            }
        }
    }

Need

    public function decodeSingle(&$apiData)
    {
        $resObj = json_decode($apiData);
        
        if (isset($resObj->error)) {
            $msg = "Error " . $resObj->error->code . " " . $resObj->error->message;
            
            if (isset($resObj->error->errors[0])) {
                $msg .= " : " . $resObj->error->errors[0]->reason;
            }

            throw new \Exception($msg);
            
        } else {
            $itemsArray = isset($resObj->items) 
                ? $resObj->items 
                : null;
            
            if ( ! is_array($itemsArray) || count($itemsArray) == 0) {
                return false;
            } else {
                return isset($itemsArray[0]) ? $itemsArray[0] : false;
            }
        }
    }
@alaouy
Copy link
Owner

alaouy commented Sep 19, 2023

@shabuninil Pull requests with tests are always welcome ;)

@andach-andreas
Copy link

Is this a change in the API, should I downgrade or something until a fix is in place?

giltotherescue added a commit to giltotherescue/Youtube that referenced this issue May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants