If I disable the Comment module, I get multiple PHP 7.4 warnings at line 123 and several others in field_views_field_default_views_data():
Trying to access array offset on value of type null in field_views_field_default_views_data()
This happens when I rebuild the cache, for example. From a quick look, entity_get_info('comment') returns NULL if the Comment module is disabled.
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | views-n3153312-40.interdiff.txt | 990 bytes | damienmckenna |
| #40 | views-n3153312-40.patch | 879 bytes | damienmckenna |
| #35 | interdiff-23-35.txt | 694 bytes | solideogloria |
| #35 | views-php74-3153312-35.patch | 957 bytes | solideogloria |
| #23 | views-php74-3153312-23.patch | 811 bytes | solideogloria |
Comments
Comment #2
damienmckennaentity_get_info('comment') is only in modules/comment/views_plugin_row_comment_view.inc, which should only be loaded if a view touches Comment data. Might you still have some views enabled which query Comment data?
Comment #3
kevin morse commentedI am also seeing this warning.
Also running PHP 7.4 and also have the Comment module disabled. Is there any way to add more info to the log file to see which View is responsible? I checked all the Views that I created and none should be accessing the Comment module.
Comment #4
damienmckennaYou might check if the "Recent comments" view is enabled.
Comment #5
trevorbradley commentedI similarly had to enable the Comments module on a site that didn't use comments to make this error go away.
The Recent Comments view was disabled.
Comment #6
alfazaz commentedI have the same warning on php 7.4.8 with comment module enabled on cache clear :
Notice : Trying to access array offset on value of type null in field_views_field_default_views_data() (line 123 in /home/******/sites/all/modules/views/modules/field.views.inc).There are other warnings for this file at lines 123, 135, 136, 142, 143 and also
Notice : Trying to access array offset on value of type null in taxonomy_field_views_data_views_data_alter() (line 471 in /home/******/sites/all/modules/views/modules/taxonomy.views.inc).and also at lines 483 and 484...
There is no change to add to views 7.x-3.24 to make it php 7.4 totally compatible ?
Comment #7
wjackson commentedI was able to reproduce this issue on a site without the core comment module installed and installing did not resolve the issue. In my instance, the issue stemmed Corresponding Entity References (cer) module and views attempting to return entity info from field.views.inc.
$entity_info = entity_get_info($entity);I was able to resolve this by first checking if the results of entity_get_info() is not empty, if not then the script will continue to build using entity data.
Comment #8
tondeuse commentedTrying to access array offset on value of type null on lines 123, 135, 136, 142, 143 are resolved with the patch provided in #7. They flare up upon cache clear with PHP 7.4, Drupal 7.72 and Views 7.x-3.24. I would love to be able to pinpoint the origin of this issue and fix it upstream, my local site is pretty simple, but does have a fair amount of custom code.
Comment #9
derekw commented#7 removed a bunch of errors but I'm still getting them for taxonomy.views.inc
Notice: Trying to access array offset on value of type null in /var/www/drupalvm/repository/sites/all/modules/views/modules/taxonomy.views.inc on line 471
Notice: Trying to access array offset on value of type null in /var/www/drupalvm/repository/sites/all/modules/views/modules/taxonomy.views.inc on line 483
Notice: Trying to access array offset on value of type null in /var/www/drupalvm/repository/sites/all/modules/views/modules/taxonomy.views.inc on line 484
Notice: Trying to access array offset on value of type null in /var/www/drupalvm/repository/sites/all/modules/views/modules/taxonomy.views.inc on line 484
Comment #10
kevster commented#7 - that seems to have fixed my issue thanks on a commerce site running 7.72 and views 3.24 on PHP 7.4
I now have another one ref entityreference - very similar
Comment #11
Kashalinka commentedPatch #7 worked for me. Am running Drupal 7.74 with PHP 7.4.12. Thanks very much, wjackson.
Comment #12
klausiWe saw the same PHP warnings when testing with PHP 7.4 and noticed that we had a couple of modules disabled where the fields were still active. We will probably use an update function similar to this to clean that up:
Comment #13
solideogloria commentedRather than putting everything inside an if block, I think it looks cleaner to use
continue;. Marking RTBC, since the code is functionally the same.Comment #14
solideogloria commentedComment #15
klausiI think the patch only covers up a problem in your system: you have active fields that refer to not existing entity types.
Would it make sense to write a watchdog() message before the "continue;"? Like "Field @field_name refers to not existing entity type @type. You might want to remove this broken field."
Comment #16
solideogloria commentedI debugged to see which it was. The fieldname is
comment_bodyand the entity iscomment. The Comment module was previously installed but now is not.Using the following (from #12) worked:
Comment #17
solideogloria commentedAdded watchdog message as a warning. I was a bit unsure whether to do notice or a warning.
Comment #18
rasikap commentedPatch #17 works for me.
Comment #19
oadaeh commentedThe wording of this is odd: "...refers to not existing entity type..."
I think it would read better to use: "...refers to a nonexistent entity type..."
or: "...refers to an entity type that does not exist..."
Comment #20
solideogloria commentedAh, yeah I just copied #15's suggestion
Comment #21
argiepiano commentedPatch #17 helped me debug and fix this issue. In my case, instances of the field were still in use in other existing entity types, so deleting the field was not an option. The nonexistent entity type was defined by a module that was no longer installed. The solution for me consisted in finding the instance entry in the SQL table field_config_instance and manually removing it. I realize acting directly on the database is not recommended, but I couldn't find any other solution.
field_info_instancedid not return anything, and thereforefield_delete_instancedid not work.Comment #22
solideogloria commentedImproved log message wording.
Comment #23
solideogloria commentedDecided it's better with emphasized variables (
%instead of@). Also, I got the comment # correct this time.Comment #24
solideogloria commentedTo address the concerns in #21, I found that I needed to call
field_read_instances()directly and useinclude_inactive.The following code works to fix the underlying data issue (by deleting the broken field instance), AND it only deletes the field if the last instances where it was used were just deleted.
The parameters
$field['field_name']and$entityvariables are the same as in the place where this patch applies. In other words, the values shown in the watchdog warning message can be substituted into the code directly and run.If someone else can verify the above code, we could include the code in the watchdog message or something.
Comment #25
ckoharj commented#23 gives another error now when caches are cleared
Field comment_body refers to nonexistent entity type comment. You might want to remove this broken field.
Error goes away if Comments module is enabled so it seems best solution is to just enable Comments module
Comment #26
solideogloria commented@ckoharj It is supposed to give that warning. This is because there is a data issue that you have to fix manually. Read the comments, and read #24 for the data fix.
Comment #27
ckoharj commentedThanks @solideogloria but I don't understand how to remove that broken field
Field comment_body refers to nonexistent entity type comment. You might want to remove this broken field.
Comment #28
solideogloria commentedUse the Devel module, go to /devel/php, and run the following code:
Make sure to disable or remove the Devel module on production sites after you are done doing this.
Comment #29
ckoharj commented@solideogloria thank you for your time.
That fixed it
Comment #30
Kashalinka commentedPatch #24 worked for me. Thanks, solideogloria. Your work is much appreciated.
Comment #31
solideogloria commentedDo people think that the code in #28 should be included anywhere? Maybe as a hyperlink/action in the log messages?
Comment #32
damienmckennaIt could be added as a documentation page, with the error message linking to that page?
Comment #33
solideogloria commentedI created a new documentation page.
https://www.drupal.org/docs/7/modules/views/data-fix-field-field-refers-...
Once it has been reviewed, I can update the patch so the log message points to it.
Comment #34
damienmckennaThe docs page has been published, thank you for putting that together!
Comment #35
solideogloria commentedComment #36
adalbertov commentedHello Just checked the latest patch (#35). It was properly pointing to the right URL in the comments and at least for me the doc seems ok, so I'm moving the issue to RTBC
Comment #37
renatog commentedWe need to change the array to the new syntax
array('%field_name' => $field['field_name'], '%type' => $entity),Using
Comment #38
solideogloria commentedDrupal 7 still supports older versions of PHP that are pre-5.4. This module doesn't specify
php=5.4in the info file, so it still should support those older versions.Comment #39
damienmckennaAgreed - there are a lot of Drupal 7 sites stuck on PHP 5.3 that can't move off it, breaking compatibility for a minor change like this doesn't make sense.
Comment #40
damienmckennaI wonder would it be better to list the node ID for the docs page, in case the URL changes? That would make it https://www.drupal.org/node/3200406.
Comment #42
damienmckennaCommitted. Thank you.
Comment #44
headbank commentedI assume the code snippet in #28 could also be run using
drush php-evalordrush php-script?If so maybe worth mentioning that as an option in the documentation page, to save installing Devel module.
Just a thunk...
Comment #45
solideogloria commentedI think that's obvious. Feel free to put the code all one one line and run using Drush.
Comment #46
loopy1492 commentedI just downloaded a fresh views 7.x-3.x-dev for our PHP 8 upgrade and I am getting this after updates:
Drupal 7.8.9.
Comment #47
damienmckenna@loopy1492: Please open a new issue for that. Thank you.
Comment #48
dangur commentedAnd for those who need a modern PHP array syntax with brackets: