I am creating a complex workflow, where a date must be added in phase 2. When the Workflow is transitioned to this phase, the user receives an error.
Notice: Uninitialized string offset: 0 in date_entity_metadata_struct_getter() (line 587 of ../sites/all/modules/date/date.module).
It doesn't appear to affect the ability to add a date. There is no default date for the field, and a date isn't required. The date is set to -3, +3.
This is the function at line 586.
function date_entity_metadata_struct_getter($item, array $options, $name, $type, $info) {
$value = trim($item[$name]);
if (empty($value)) {
return NULL;
}If nothing else, I would like to stop this particular warning message.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | date-n2074457-16.patch | 554 bytes | damienmckenna |
| #15 | interdiff.txt | 840 bytes | nedjo |
| #15 | uninitialized_string_offset_in_date_entity_metadata_struct_getter-2074457-15.patch | 803 bytes | nedjo |
Comments
Comment #1
nels commentedI got this error when evaluating a Date field in a Rules Component.
I added a condition to check that the value was not empty.
Example Rule order:
Comment #2
johnlaine commentedI am also getting this error when using a rules component to check if the data value is empty.
I changed this line
$value = trim($item[$name]);To
$value = (isset($item[$name])) ? trim($item[$name]) : '';This prevented the error message for me.
I don't know how to test it or submit a patch yet, will do so asap, unless someone else would like to.
Comment #3
rovo89 commentedI have noticed the same warning on two of my sites using version 2.8. In both cases, the fields are empty by default, they're set to #access = FALSE and an entity_metadata_wrapper is created in hook_node_update.
Please find my patch attached. I think the value for a date field can't be a string, it should be an array. Using NULL as default value also removes the warnings - not sure what's better here.
Comment #4
crstnkal commentedI currently have Drupal version: 7.50 and I get 2 messages:
@rovo89 the patch worked successfully!!!
Comment #5
akolahi commentedPatch works for me as well
Comment #6
damienmckennaRerunning the tests, lets see how this works.
Comment #7
damienmckennaComment #8
anrikun commentedI get the same errors as @crstnkal at #4.
Unfortunately, even with patch at #3, I still get:
Warning : Illegal string offset 'value' in date_entity_metadata_struct_getter()Comment #9
anrikun commentedHere's a new patch.
Comment #10
yazzbe commented#9 fixes the problem in Date 7.x-2.10
Comment #11
mdolnik commentedFYI the changes in #3's
date-default-value-2074457-3.patchare also present in the patch in Issue: String Offset errors on edit page using PHP 7.1.0Comment #12
tame4tex commentedEven with https://www.drupal.org/project/date/issues/2843367#comment-12929035 patch applied I am still getting the PHP Notices & Warnings mentioned by #4 on version 7.x-2.10.
Patch supplied in #9 stops the PHP notices and warnings but I wonder if it is just fixing the symptom and not the root cause.
Comment #13
tame4tex commentedApplying patch #3 stops the PHP notices and warnings with Date version 7.x-2.10, Drupal 7.67 and PHP 7.2.
I am thinking this is a better patch than #9 because it is fixing the root cause.
@anrikun I would be interested in knowing more details of when you were getting the php warnings.
Comment #14
anrikun commented@tame4tex
It's been a while ago so I can't remember precisely.
I think I had found cases when value was simply not set yet, so checking
isset()seemed to be the best protection.Comment #15
nedjoOn PHP 7.4 the same bug may produce a different error message:
Setting
$valuewithin theifcontrol structure means it will be undefined in theFALSEcase.Attaching a new patch that combines the new
isset()test with the existing one for an empty value and returns early.Comment #16
damienmckennaYou shouldn't use empty() on the return from another function, it is only meant to be used on variables.
How about this?
Comment #17
damienmckennaI think we should add this to 2.12.
Comment #18
solideogloria commentedComment #20
damienmckennaCommitted. Thank you.
Comment #22
zevarix commentedI tried the patch on comment #16 on and the Undefined index PHP notice still persisted on every save of a content type with event dates and times.
Notice: Undefined index: field in date_entity_metadata_struct_getter() (line 669 of /code/docroot/sites/all/modules/contrib/date/date.module).Drupal 7.80
Date 7.x-2.11
PHP 7.3.27
Comment #23
damienmckenna@zevarix: Please open a new issue, that's something else.