Problem/Motivation
after upgrade to php 8.1 with core 9.3.7
i've got the following error due to deprecated null input value
Deprecated function: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in Drupal\Core\Extension\ExtensionPathResolver->getPath() (line 85 of /var/www/subsite/web/core/lib/Drupal/Core/Extension/ExtensionPathResolver.php)
#0 /var/www/subsite/web/core/includes/bootstrap.inc(346): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 /var/www/subsite/web/core/lib/Drupal/Core/Extension/ExtensionPathResolver.php(85): dirname()
#3 /var/www/subsite/web/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php(123): Drupal\Core\Extension\ExtensionPathResolver->getPath()
#4 /var/www/subsite/web/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php(87): Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension()
#5 /var/www/subsite/web/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php(66): Drupal\Core\Asset\LibraryDiscoveryCollector->getLibraryDefinitions()
#6 /var/www/subsite/web/core/lib/Drupal/Core/Cache/CacheCollector.php(149): Drupal\Core\Asset\LibraryDiscoveryCollector->resolveCacheMiss()
#7 /var/www/subsite/web/core/lib/Drupal/Core/Asset/LibraryDiscovery.php(44): Drupal\Core\Cache\CacheCollector->get()
#8 /var/www/subsite/web/core/lib/Drupal/Core/Asset/LibraryDiscovery.php(58): Drupal\Core\Asset\LibraryDiscovery->getLibrariesByExtension()
#9 /var/www/subsite/web/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php(68): Drupal\Core\Asset\LibraryDiscovery->getLibraryByName()
#10 /var/www/subsite/web/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php(70): Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies()
#11 /var/www/subsite/web/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php(41): Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies()
#12 /var/www/subsite/web/core/lib/Drupal/Core/Asset/AssetResolver.php(104): Drupal\Core\Asset\LibraryDependencyResolver->getLibrariesWithDependencies()
#13 /var/www/subsite/web/core/lib/Drupal/Core/Asset/AssetResolver.php(116): Drupal\Core\Asset\AssetResolver->getLibrariesToLoad()
#14 /var/www/subsite/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(312): Drupal\Core\Asset\AssetResolver->getCssAssets()
#15 /var/www/subsite/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(158): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAssetLibraries()
#16 /var/www/subsite/web/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments()
#17 [internal function]: Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond()
#18 /var/www/subsite/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#19 /var/www/subsite/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#20 /var/www/subsite/vendor/symfony/http-kernel/HttpKernel.php(179): Symfony\Component\HttpKernel\HttpKernel->filterResponse()
#21 /var/www/subsite/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#22 /var/www/subsite/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#23 /var/www/subsite/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#24 /var/www/subsite/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#25 /var/www/subsite/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#26 /var/www/subsite/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#27 /var/www/subsite/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#28 /var/www/subsite/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#29 /var/www/subsite/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#30 /var/www/subsite/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#31 {main}
Steps to reproduce
upgrade to php 8.1 with core 9.3.7
Proposed resolution
handling dirname function to accept null value or replace null with empty string
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #54 | drupal-3268634-d11-54.patch | 737 bytes | vladimiraus |
| #53 | drupal-3268634-53.patch | 733 bytes | vladimiraus |
| #47 | 3268634-dirname-null-deprecated-47.patch | 14.98 KB | firewaller |
| core_dirname.patch | 14.28 KB | mok7tar | |
| #31 | core-dirname-3268634-0.patch | 14.86 KB | taraskorpach |
Issue fork drupal-3268634
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
longwaveThe NULL in question is returned by ExtensionPathResolver::getPathname()
This should only return NULL in two cases:
or
Which of these errors was triggered in your case?
Comment #3
mok7tar commentedi think it first case
Comment #4
anprok commentedHelped me with error message on php 8.1 and core 9.3.11
Comment #6
andregp commentedI believe the test fail was random, restoring status...
Comment #10
anprok commentedComment #11
longwaveI don't believe forcing an empty string to be passed is the right fix. Instead we should figure out why these functions are being called with NULL in the first place, as that seems like the real bug.
I also think in cases like this we should consider introducing typed parameters on the methods in question, which should raise a TypeError closer to the source of the problem.
Comment #12
Christopher Riley commentedShould this patch apply cleanly on Drupal 9.4.1 because I am seeing a fail when I do the composer patch.
Comment #13
anprok commentedYou can use this patch from merge request in Drupal 9.4.x https://git.drupalcode.org/project/drupal/-/merge_requests/2474.diff
Comment #14
larowlanPSA don't use this URL directly, as anyone can push to that branch you're opening your project up to supply chain attacks. Instead wget the patch and store it in your repo and reference the file instead from composer patches.
Comment #15
robcarrThe patch applies to 9.4.5.
Not an expert on collateral issues in core, but sorted my problem out running site under PHP 8.1.8
RTBC?
Comment #16
eduardo morales albertiAs longwave says, the steps to reproduce the error should be more clear to know why the params are null when should not be NULL.
I saw multiple fixes like this one (convert to string NULL values) and I think is a "workaround" to silence the warnings, but not a solution to the problem.
Comment #17
gordon commentedI had this issue for a client site. But this was a secondary issue which was caused by a bug earlier on.
We should not be just setting the NULL to '' to just obfuscate the real issue. If you are getting these errors it is because you have an issue. Maybe a @longwave put it to add in some triggering errors would be a better idea as I see in the future as more people move to PHP 8.1, they will turn off the depreciated errors and just ignore this issue.
Comment #19
ravi.shankar commentedRebased the current MR, keeping the status needs work for comment #17
Comment #21
sophron commentedDrupal Version: 9.5.2 | PHP Version:8.1.13
Steps to Reproduce the Error
Error Message 1: Deprecated function: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in Drupal\Core\Extension\ExtensionPathResolver->getPath() (line 85 of core/lib/Drupal/Core/Extension/ExtensionPathResolver.php).
Error message 2: User warning: The following theme is missing from the file system: ckeditor in Drupal\Core\Extension\ExtensionPathResolver->getPathname() (line 63 of core/lib/Drupal/Core/Extension/ExtensionPathResolver.php).
Comment #22
ankitv18 commentedW.r.t comment #21, I've encountered Error Message 2 while using Site Studio 7.0.x
Drupal version: 10.0.2
Site Studio: 7.0.0
CKEditor 5
PHP: 8.1.11
Comment #23
jmohino commentedI have the same error with jquery_ui_draggable, line 63 in file ExtensionPathResolver.php. You would also have to change line 58 of the file in the patch:
User warning: The following theme is missing from the file system: jquery_ui_draggable en Drupal\Core\Extension\ExtensionPathResolver->getPathname() (línea 63 de /var/www/html/miguelturra/web/core/lib/Drupal/Core/Extension/ExtensionPathResolver.php)Comment #24
aiphesHello,
After enabled , I get this error too:
Result on:
Deprecated function : dirname(): Passing null to parameter #1 ($path) of type string is deprecated dans Drupal\Core\Extension\ExtensionPathResolver->getPath() (/home/xxx/www/xxx/sited9/web/core/lib/Drupal/Core/Extension/ExtensionPathResolver.php ligne 85)D953 + PHP 8.1.6
Thanks
Comment #25
cilefen commentedWe need the root cause and verified steps to reproduce that begin with “Install Drupal” that you have actually reproduced. I think that situation has not changed since comment #11.
Comment #26
cilefen commentedIt could be this unusual library definition.
Comment #27
tritof commentedHello,
After Upgrading Drupal 9.3 > 9.5 + modules (PHP 8.1.13), I had the same double warning issue :
User warning: The following theme is missing from the file system: jquery_ui_autocomplete in Drupal\Core\Extension\ExtensionPathResolver->getPathname() (line 63 of core/lib/Drupal/Core/Extension/ExtensionPathResolver.php).Deprecated function: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in Drupal\Core\Extension\ExtensionPathResolver->getPath() (line 85 of core/lib/Drupal/Core/Extension/ExtensionPathResolver.php).User warning: The following theme is missing from the file system: jquery_ui_menu in Drupal\Core\Extension\ExtensionPathResolver->getPathname() (line 63 of core/lib/Drupal/Core/Extension/ExtensionPathResolver.php).Deprecated function: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in Drupal\Core\Extension\ExtensionPathResolver->getPath() (line 85 of core/lib/Drupal/Core/Extension/ExtensionPathResolver.php).Both modules jquery_ui_autocomplete and jquery_ui_menu were required and downloaded during update without activation (https://www.drupal.org/project/jquery_ui_autocomplete/issues/3328939).
Once the modules activated, all the warnings disappeared, including "Deprecated function: dirname(): Passing null to parameter #1..."
Comment #28
lubwn commentedI had this error with jquery_ui_slider and indeed as stated in #27 actually downloading the module and enabling it, even when not used anywhere on the website it solved the errors present in dblog / occasionaly presented on frontend.
I wonder why / how this happens but so far this is a good solution for me.
Comment #29
loopy1492 commentedWe were getting this error on the reports page. I assume it was actually the admin menu? Not sure. Either way, enabling jquery_ui_menu did the trick. Not sure why updb never enabled the module for us if it was suddenly required for some functionality to work.
We are on PHP 8.1 and Core 9.5.5.
Both of these errors were on...
Location /admin/reports/updates
Referrer /admin/reports
Comment #30
jwilson3We're getting this error message when testing Drupal 9 with Site Studio 7, where we have not yet enabled CKeditor 5 module (because we're not on Drupal 10 yet).
Comment #31
taraskorpachJust re-roll the patch for D10.1.x
Comment #32
bwoods commentedI ran into this same problem, and it seemed at first if the patch in #31 worked. However, when I looked a little more closely, I realized the actual issue was that my custom theme was calling two libraries that were not actually enabled (one via a module, one via a theme). These calls were outdated, so once I removed, the notice disappeared, even without this patch.
Comment #33
sokru commentedStill an issue with 10.1.7. From production logs I noticed the issue was triggered by wrong query parameter on aggregated css/js assets. Oddly it was adding query parameter
&theme=site_b, when the only available theme issite_a. We have two drupal platforms, which are hosted by different vendors, but authentication is done with Samlauth/SSO, which indicates the user was first logged into site_b and then arrived to site_a which caused the wrong query parameter to be generated.Comment #34
sagesolutions commentedI ran into this issue as well. Turns out I still had
{{ attach_library('classy/node') }}in my twig template files which was causing the issue. The issue disappeared once I removed that line from all my template files.
Comment #35
smulvih2#31 works for my on 10.2.5
Comment #36
ericdsd commentedPatch #31 Works on 10.2.7 too
+1 for RTBC
Comment #37
summit commentedHi, I think this patch is also needed on new drupal 10.3.0.
After installing that version, this depreciation message occurs.
Made issue for drupal 10.3 on https://www.drupal.org/project/drupal/issues/3457370
Greetings,
Comment #38
hungdo commentedRerolling for 10.3
Comment #39
chippyjacob commented#31 works for Drupal 10.2
Comment #40
andreastkdf commented#38 works on 10.3.1
+1 for RTBC
Comment #41
anybody@cilefen re #26 is there a related issue in that project or was that fixed in the meantime?
Eventually related to #3337831: The following theme is missing from the file system: jquery_ui_draggable?
Comment #42
scottsawyerI had a similar problem with jquery_ui_accordion, library not loading, missing theme extension, passing null to dirname(). I installed the patch, which did not immediately fix the problem. I disabled then re-enabled jquery_ui_accordion, and it started loading the library. I removed the patch and it still works. I think Drupal just needed a brain flush, and now I do too.
Not sure if this should be committed, but maybe keep it open for visibility?
Comment #43
firewaller commented+1
Comment #44
eduardo morales albertiThe problem is that the library does not exist because it was removed or is not loaded properly, so it should be captured and trigger a warning indicating what library is failing instead of the current Deprecated function: dirname() message.
Comment #45
drale01 commentedI had the same issue with my custom theme, and the error disappeared after I removed a non-existent library reference.
Fix for my issue
Comment #46
firewaller commentedWe've been seeing this issue for months since the upgrade. There is no indication of which module or library is being incorrectly called, so I agree with @eduardo-morales-alberti that the messaging needs to be updated or a separate log needs to be added. Is there any tool or mechanism for identifying the incorrect module or library?
Comment #47
firewaller commentedI just realized that patch #38 wasn't a complete reroll of the previously working patch for #31. I've rerolled #31 for 10.3
This should just bypass the warning, but it doesn't resolve the underlying issue which I think should be addressed in this issue or a followup issue.
Comment #48
smustgrave commentedSteps still appear to be missing from summary.
Not sure we should be putting empty checks on every call. We should research which spot is causing the problem and backtrace why the value is null. So we aren’t masking a different issue
Comment #49
firewaller commentedI agree actually. I don't want to cover the issue up. I just wanted to fix the partial reroll from #38, but I'm all ears for suggestions to identify these invalid modules/libraries.
Comment #50
goldI was just going to update the description with the steps to reproduce from #21 and I note that both #21 and #22 list contrib modules.
Is it possible to replicate this issue with a clean install of Drupal Core alone?
Comment #51
kartagisIn regard to #21, I am getting both the errors only when I install my webform related custom module. UPDATE: It seems that I was getting the error because of a typo. I corrected that typo and I'm now getting a warning.
Comment #53
vladimirausUpdated patch for 10.6
Comment #54
vladimirausD11.3 patch
Comment #55
sivaji_ganesh_jojodae commentedThe issue summary indicates the version as main, while the merge request targets the 9.4.x branch. Am I missing something here?
Additionally, according to the contribution policy, code changes should be submitted through a merge request rather than patches.
Comment #58
andreastkdf commentedUpdated the fork with
mainbranch from upstream and opened a new MR from new branch3268634-deprecated-function-dirname-main-branchand targetingmain, including the fix.Comment #59
smustgrave commentedThanks but this ticket also needs updated steps to reproduce this. Depending on that will probably determine if we need test coverage
Comment #60
andreastkdf commentedbtw, I updated the method definitions as file could be NULL on loadFile (case when css_asset['data'] does not exist)
Comment #61
andreastkdf commented@smustgrave, about your re-#59:
I opened the MR mainly to refresh the patch against latest core.
However, after looking at it more closely, I do not think this is the right fix. Making
loadFile()accept NULL and changingdirname($file)todirname($file ?? '')just suppresses the deprecation when$fileis unexpectedly NULL.From the comments above, it looks like the real issue is usually upstream: Drupal is trying to resolve a library or extension that does not actually exist, for example, because of an invalid library definition, outdated theme reference, or missing contrib/module code.
The patches and direction on this issue do not address the underlying problem, since
$fileis still then passed tofile_get_contents()and$base_pathis derived from a non-path value. In other words, this masks the symptom rather than fixing where the invalid input originates.Comment #62
smustgrave commentedExcellent investigative work! We 100% want to address the problem and not mask it.