WsdlToPhp / PackageGenerator

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

TypeError when iterating over an empty ArrayType #277

Closed pbowyer closed 1 year ago

pbowyer commented 1 year ago

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 https://github.com/WsdlToPhp/PackageBase/pull/38 and https://github.com/WsdlToPhp/PackageGenerator/issues/248.

mikaelcom commented 1 year ago

fixed in PackageBase@5.0.3 thanks to https://github.com/WsdlToPhp/PackageBase/pull/38