Repository navigation
Conversation
Functions from a ModuleHandlerInterface::loadInclude() file were only known because the LoadIncludes rule ran require_once on it. A project that only includes extension.neon, or turns off drupal.rules.loadIncludes, got "Function ... not found" for them. - IncludeLoader resolves and loads the file once and keeps the result, so the rules and the extension report the same outcome. - ModuleHandlerLoadIncludeReturnTypeExtension, in extension.neon, loads the file whenever the call is analyzed. - LoadIncludes and ModuleLoadInclude use IncludeLoader. Their messages and identifiers don't change. module_load_include() keeps loading through its rule only: it was removed in Drupal 11. Fixes #741. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Closing in favor of a README fix. #741 came from a manual setup that included only |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #741.
Functions declared in a file loaded by
ModuleHandlerInterface::loadInclude()were only known to PHPStan because theLoadIncludesrule ranrequire_onceon the file. Without that rule, calls to them fail:That happened in two cases:
extension.neon. The README's manual installation section presentsrules.neonas optional. This is what Drush hit, and they worked around it by registeringLoadIncludesby hand.drupal.rules.loadIncludes: false. Turning off a rule shouldn't add errors.phpstan/extension-installerincludes both files, so most projects never saw it.Change
IncludeLoaderresolves the module and file of aloadInclude()call, loads it withrequire_once, and keeps the result for each file. PHP won't run a file twice, so whichever caller runs first, the rule or the extension, the other gets the same result. Before, a file that threw while loading was only reported the first time.ModuleHandlerLoadIncludeReturnTypeExtensionis registered inextension.neon. PHPStan resolves the return type of everyloadInclude()call, so the file is loaded whether or not the rule runs. The return type doesn't change.LoadIncludesandModuleLoadIncludeuseIncludeLoader. Their messages and identifiers are the same.loadIncludestoggle comment now says the include is loaded either way.module_load_include()still only loads through its rule. It was removed in Drupal 11, so it only matters on Drupal 10, which reaches end of life next month.Tests
LoadIncludeWithoutRulesTestruns only PHPStan'sCallToNonExistentFunctionRuleon a call to a function fromphpstan_fixtures.loader.inc. It fails onmainwith "Function phpstan_fixtures_function_from_load_include not found." It passes with the extension, and fails again with the extension untagged. The include file is only used by this test, so another test can't have loaded it first.LoadIncludesRuleTestandModuleLoadIncludeRuleTestpass unchanged.php vendor/bin/phpunit(924 tests),phpcsandphpstan analyzepass.Drush
Drush can drop the hand-registered
LoadIncludesrule after this. Drush also excludessrc/Commands/core/LanguageAddCommand.phpwith the note "Unclear why the phpstan-drupal rule is not working". That one isn't this bug: the failing call isdrush_locale_translation_default_update_options(), which Drush defines in its ownincludes/legacy.inc. It needsscanFiles: [includes/legacy.inc].🤖 Generated with Claude Code