WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
422 stars 73 forks source link

An type exception is raised when we try to navigate in a AbstractStructArrayBase using a php foreach #248

Closed maurobn closed 1 year ago

maurobn commented 3 years ago

It occurs only in PHP8. When we try to navigate in a AbstractStructArrayBase, usinf for in a twig template, on using foreach in a php code, an incompatible type exception is raised. When the array object is initialized, the initInternArray of the abstract class AbstractStructArrayBaseis called for the first time, with no parameter. In these situation, the execution flows to the elseif branch, and once again, recursively, initInternArray is called again, this time with parameter.

He an exception is raised because AbstractStructArrayBase doesn't match array type (this classes doesn't implement AbstractObject, so it's no possible to pass such object as an array).

private function initInternArray($array = [], bool $internCall = false): self
{
    if (is_array($array) && count($array) > 0) {
        $this
            ->setInternArray($array)
            ->setInternArrayOffset(0)
            ->setInternArrayIsArray(true);
    } elseif (!$this->internArrayIsArray && !$internCall && property_exists($this, $this->getAttributeName())) {
        $this->initInternArray($this->getPropertyValue($this->getAttributeName()), true);
    }

    return $this;
}

To Reproduce To get the exception raised, just use an AbstractStructArrayBase child (a concrete class) in a foreach loop. foreach($childAbstractStructArrayBase as $item) { .... }

Expected behavior To be possible to use an AbstractStructArrayBase in a foreach loop.

Additional context Add any other context about the problem here.

mikaelcom commented 3 years ago

Could you paste the PHP code of the class inheriting from the AbstractStructArrayBase class? And the code creating the object inheriting from the AbstractStructArrayBase class ?

Because normally the property, namely returned by $this->getAttributeName(), should be initialized as an array. So the $this->getPropertyValue($this->getAttributeName()) call returns an array. This is taken care of when the inherited classes are generated from a WSDL.

mikaelcom commented 1 year ago

no feedback, feel free to reopen