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

Undefined array key #13

Open
devmal opened this issue May 19, 2022 · 0 comments
Open

Undefined array key #13

devmal opened this issue May 19, 2022 · 0 comments

Comments

@devmal
Copy link

devmal commented May 19, 2022

Ve třídě "ZboziKonverze" v metodě "setOrder($orderAttributes)" se přistupuje i k prvkům pole "deliveryType", "deliveryPrice", "otherCosts" a "paymentType". Tyto prvky ale nejsou povinné parametry.

public function setOrder($orderAttributes) 
{
        if (array_key_exists("email", $orderAttributes) && $orderAttributes["email"]) {
            $this->email = $orderAttributes["email"];
        }
        $this->deliveryType = $orderAttributes["deliveryType"];
        $this->deliveryPrice = $orderAttributes["deliveryPrice"];
        $this->orderId = $orderAttributes["orderId"];
        $this->otherCosts = $orderAttributes["otherCosts"];
        $this->paymentType = $orderAttributes["paymentType"];
}

Protože nejsou povinné, nelze očekávat, že je pole bude vždy obsahovat (nebyly zadány).
PHP 8.x pak hlásí PHP Warning: Undefined array key "deliveryType" apod.

Patrně bude potřeba ošetřit pomocí array_key_exists(), tak jako tomu je u prvku "email".

unabombe added a commit to unabombe/zbozi-konverze that referenced this issue Jun 16, 2022
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

1 participant