Skip to content

fix: disable autoloading in typeIsValid to prevent fatal errors during generation#16

Merged
mikaelcom merged 1 commit into
WsdlToPhp:developfrom
aldenw:fix/disable-autoload-in-type-validation
Mar 21, 2026
Merged

fix: disable autoloading in typeIsValid to prevent fatal errors during generation#16
mikaelcom merged 1 commit into
WsdlToPhp:developfrom
aldenw:fix/disable-autoload-in-type-validation

Conversation

@aldenw
Copy link
Copy Markdown
Contributor

@aldenw aldenw commented Mar 12, 2026

Problem

TypeHintedElementTrait::typeIsValid() calls class_exists($type) which triggers the PHP autoloader by default. When used by wsdltophp/packagegenerator to generate code from a WSDL, this can cause fatal errors when a freshly-generated class file is autoloaded and its parent class hasn't been generated yet.

The call chain is: PhpFunctionParameter::setType()typeIsValid()class_exists($type) → autoloader includes the generated file → PHP tries to resolve extends ParentTypefatal error if the parent class file hasn't been written yet.

Fix

Pass false as the second argument to class_exists() to disable autoloading:

// Before
|| (is_string($type) && class_exists($type))

// After
|| (is_string($type) && class_exists($type, false))

This has no impact on validation effectiveness — the subsequent stringIsValid() check validates the type string format, and class_exists($type, false) still matches classes that are already loaded in memory.

@mikaelcom
Copy link
Copy Markdown
Member

Hello,
Thanks for your PR.
I just added coverage analyses, can you rebase from develop in order to see if it still works well?

…g generation

class_exists() in typeIsValid() triggers the autoloader, which can cause
fatal errors during code generation when a freshly-generated class extends
a parent class that hasn't been generated yet. The generation order of
structs is non-deterministic, so this produces intermittent failures.

Passing false as the second argument to class_exists() disables autoloading.
The subsequent stringIsValid() check still validates the type string format,
so there is no loss of validation coverage.
@aldenw aldenw force-pushed the fix/disable-autoload-in-type-validation branch from 6bd1380 to 77ae5d6 Compare March 17, 2026 15:47
@mikaelcom
Copy link
Copy Markdown
Member

please target develop branch for merging 🙏

@aldenw aldenw changed the base branch from master to develop March 17, 2026 18:20
@aldenw
Copy link
Copy Markdown
Contributor Author

aldenw commented Mar 17, 2026

Done. Rebased onto develop and retargeted the PR. Thanks for the heads up!

@mikaelcom mikaelcom merged commit e2a275c into WsdlToPhp:develop Mar 21, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants