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

TypeError: Cannot assign bool to property USPS\USPSBase::$response of type string in USPS\USPSBase->setResponse() #9

Closed
SAH62 opened this issue Apr 3, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@SAH62
Copy link

SAH62 commented Apr 3, 2023

I just ran into the subject error when trying to save a Drupal Commerce shipment. Here's the code that's involved:

    /**
     * Set the response.
     */
    public function setResponse(mixed $response = ''): self
    {
        $this->response = $response;
        return $this;
    }

The issue is that the value of $response can be a boolean value or a string value. It can be boolean FALSE if, for example, the call to curl_exec from this line in function doRequest() fails:

$this->setResponse(curl_exec($ch));

If curl_exec fails, it's returns boolean FALSE and the attempt to assign FALSE to $this->response produces the TypeError. Here's a suggested fix:

    /**
     * Set the response.
     */
    public function setResponse(mixed $response = ''): self
    {
        if (is_string($response)) {
            $this->response = $response;
        }
        else {
            $this->response = '';
        }

        return $this;
    }
@GeNyaa GeNyaa added the bug Something isn't working label Apr 11, 2023
@GeNyaa
Copy link
Owner

GeNyaa commented Apr 11, 2023

Rolled out a fix for this @SAH62 v2.0.2 should no longer have this issue.

@GeNyaa GeNyaa closed this as completed Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants