soap-client icon indicating copy to clipboard operation
soap-client copied to clipboard

Typed property ... must not be accessed before initialization

Open RiseAndCry opened this issue 9 months ago • 0 comments

Bug Report

Q A
BC Break no
Version 3.1.2

Summary

When using auto generated classes for response handling, i get this error: Typed property ...\BaseReturnType::$ReturnCode must not be accessed before initialization

Current behavior

Accessing property which has a value set does not work.

How to reproduce

Response class (auto generated):

<?php
declare(strict_types=1);

namespace ...\Type;

abstract class BaseReturnType
{
    private bool $IsOk;

    private bool $IsWarninig;

    private bool $IsError;

    private int $ReturnCode;

    private ?string $ReturnText = null;

    public function getIsOk(): bool
    {
        return $this->IsOk;
    }

    public function withIsOk(bool $IsOk): static
    {
        $new = clone $this;
        $new->IsOk = $IsOk;

        return $new;
    }

    public function getIsWarninig(): bool
    {
        return $this->IsWarninig;
    }

    public function withIsWarninig(bool $IsWarninig): static
    {
        $new = clone $this;
        $new->IsWarninig = $IsWarninig;

        return $new;
    }

    public function getIsError(): bool
    {
        return $this->IsError;
    }

    public function withIsError(bool $IsError): static
    {
        $new = clone $this;
        $new->IsError = $IsError;

        return $new;
    }

    public function getReturnCode(): int
    {
        return $this->ReturnCode;
    }

    public function withReturnCode(int $ReturnCode): static
    {
        $new = clone $this;
        $new->ReturnCode = $ReturnCode;

        return $new;
    }

    public function getReturnText(): ?string
    {
        return $this->ReturnText;
    }

    public function withReturnText(?string $ReturnText): static
    {
        $new = clone $this;
        $new->ReturnText = $ReturnText;

        return $new;
    }
}
  1. Call soap client that will return the aforementioned response
  2. Try calling getReturnCode() on it - it throws Typed property ...\BaseReturnType::$ReturnCode must not be accessed before initialization error.

When i debug this BaseReturnType (after executing request), i get such a response (partial): Screenshot 2024-05-07 at 18 14 52 (Bankruptcies comes from SubClass)

which means the values have been set (as expected).

Expected behavior

Calling getReturnCode() should return the value instead of throwing an error:


I noticed a few weird things though:

  1. if instead of calling getReturnCode() i directly access the property via $returnType->ReturnCode - it works. But it's a private variable, so... ehh ??? no Cannot access private property ... error ? i'm really confused.
  2. if i add a default value to ReturnCode (999) - it shows up as an additional variable (both in BaseReturnType and in SubClass) ??? Screenshot 2024-05-07 at 18 12 45

RiseAndCry avatar May 07 '24 15:05 RiseAndCry