soap-client
soap-client copied to clipboard
Typed property ... must not be accessed before initialization
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;
}
}
- Call soap client that will return the aforementioned response
- Try calling
getReturnCode()
on it - it throwsTyped property ...\BaseReturnType::$ReturnCode must not be accessed before initialization
error.
When i debug this BaseReturnType (after executing request), i get such a response (partial):
(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:
- if instead of calling
getReturnCode()
i directly access the property via$returnType->ReturnCode
- it works. But it's a private variable, so... ehh ??? noCannot access private property ...
error ? i'm really confused. - if i add a default value to
ReturnCode
(999) - it shows up as an additional variable (both in BaseReturnType and in SubClass) ???