Problem/Motivation

If a View has a date field added to it that is NULL, the following error triggers :
Deprecated function: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in Drupal\view_custom_table\Plugin\views\field\MysqlDate->render() (line 154 of /var/www/html/web/modules/contrib/view_custom_table/src/Plugin/views/field/MysqlDate.php)

This is due to the fact that if no date is set, $date_value ends up as NULL (which then gets passed on to strtime) :

  public function render(ResultRow $values) {
    $date_value = $this->getValue($values);
    $value = strtotime($date_value);
    ..

This is only from PHP 8.1 onwards, as 8.1 has deprecated passing null to a lot of functions (see here).

Steps to reproduce

- Create a database table with a date field, that is allowed to be set to NULL. Make sure the table has at least a single entry with a date of NULL
- Add the new database table as a Views Custom Table
- Create a View based on this new Views Custom Table, and add the date field to it
- Preview the View

Proposed resolution

Check that $date_value is not NULL before continuing the render function.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 view_custom_table-3316433-4.patch6.09 KBbogdan.dinu
Command icon 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

vodde83 created an issue. See original summary.

Rajeshreeputra made their first commit to this issue’s fork.

joseph.olstad’s picture

Status: Active » Closed (outdated)

see changes in the HEAD of 2.0.x and in the 2.0.3 release

bogdan.dinu’s picture

Version: 2.0.1 » 2.0.x-dev
Status: Closed (outdated) » Needs work
Issue tags: +strtotime php8
StatusFileSize
new6.09 KB

This is still an issue because there is no check on the value that is given to strtotime on line 155.
I attached a patch with a fix.

liam morland’s picture

Issue tags: -strtotime php8 +PHP 8.0

shivam_tiwari’s picture

Assigned: Unassigned » shivam_tiwari

shivam_tiwari’s picture

Assigned: shivam_tiwari » Unassigned
Status: Needs work » Needs review
avpaderno’s picture

Title: Deprecated function: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated » strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated
joseph.olstad’s picture

Status: Needs review » Needs work
joseph.olstad’s picture

Merge request is 7 commits behind and is blocked

shivam_tiwari’s picture

Status: Needs work » Needs review
joseph.olstad’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.