WsdlToPhp/PackageGenerator

TypeError when iterating over an empty ArrayType

pbowyer opened this issue · 1 comments

Describe the bug

Fatal error:  Uncaught TypeError: Argument 1 passed to WsdlToPhp\PackageBase\AbstractStructArrayBase::initInternArray() must be of the type array, null given, called in /var/www/html/vendor/wsdltophp/packagebase/src/AbstractStructArrayBase.php on line 270 and defined in /var/www/html/vendor/wsdltophp/packagebase/src/AbstractStructArrayBase.php:262
Stack trace:
#0 /var/www/html/vendor/wsdltophp/packagebase/src/AbstractStructArrayBase.php(270): WsdlToPhp\PackageBase\AbstractStructArrayBase->initInternArray(NULL, true)
#1 /var/www/html/vendor/wsdltophp/packagebase/src/AbstractStructArrayBase.php(149): WsdlToPhp\PackageBase\AbstractStructArrayBase->initInternArray()
#2 /var/www/html/packages/guardianjobs/src/Maple/GuardianJobs/ArrayType/ArrayOfWSHierarchicalTerm.php(123): WsdlToPhp\PackageBase\AbstractStructArrayBase->first()
#3 /var/www/html/jbengine/JobBoards/GuardianJobs.class(105): Maple\GuardianJobs\ArrayType\ArrayOfWSHierarchicalTerm->first()
#4 /var/www/html/jbengine/JobBoards/GuardianJobs.class(129): GuardianJobs->toKe in /var/www/html/vendor/wsdltophp/packagebase/src/AbstractStructArrayBase.php on line 262

To Reproduce
Generate the package from the WSDL (will email the URL). I'm using PHP 7.4
Authenticate
Fetch the category terms for a category

if ($this->soapGetter->GetHierarchicalCategoryTerms(new \Maple\GuardianJobs\StructType\GetHierarchicalCategoryTerms($this->uiSecurityToken, (string)$category->getID())) === false) {
    $this->handleError($this->soapGetter->getLastError());
} else {
    $terms = $this->soapGetter->getResult()->getGetHierarchicalCategoryTermsResult();
}

Iterate over the terms and their children

foreach ($terms as $categoryTerm) {
    $result[$categoryTerm->getID()] = $valuePrefix . $categoryTerm->getName();
    /** @var ArrayOfWSHierarchicalTerm $children */
    if ($children = $categoryTerm->getChildren()) {
        // This is where it goes wrong and the TypeError is thrown when I try to do anything with $children
        //dump($children->count());
        //$result += $this->toKeyValue($categoryTerm->getChildren(), $valuePrefix . $categoryTerm->getName() . ' > ');
    }
}

Expected behavior
No TypeError.

Additional context
Add any other context about the problem here.

wsdltophp/domhandler             2.0.6      Decorative design pattern to ease DOM handling
wsdltophp/packagebase            5.0.2      Contains the base classes to be used by classes generated by wsdltophp/packagegenerator
wsdltophp/packagegenerator       4.1.5      Generate hierarchical PHP classes based on a WSDL
wsdltophp/phpgenerator           4.1.1      Generate php source file
wsdltophp/wsdlhandler            1.0.5      Decorative design pattern to ease WSDL handling

A var_export() of $terms is posted at https://gist.github.com/pbowyer/d9831be7d08af4060eb9a1b4a1f3218b

I presume this error is related to WsdlToPhp/PackageBase#38 and #248.