Skip to content

PHP 7.4 Notice warning for accessing a Array Offset when Array is null  #448

@A-Matt

Description

@A-Matt

Accessing a Page Edit screen returns the following between the Name & the URL, however this issue likely can be caused in more places where the get_var function does not return a row.
Notice: Trying to access array offset on value of type null in <dir>\html\wp-includes\wp-db.php on line 2612 (Please note the line maybe slightly off due to a minor edit within our config)

	if(false === $result)
		return null;

	$row = sqlsrv_fetch_array( $result );
	return $row[ 0 ];   // <---- This line
}

"SELECT TOP 1 post_name FROM wp_posts WHERE post_name = '<POSTNAME>' AND post_type IN ( 'page', 'attachment' ) AND ID != 5227 AND post_parent = 4882"
is the Failing SQL Query in my case. This is likely to no rows returned and can be fixed by changing it to:

Fix

return sqlsrv_has_rows( $result ) ? $row[ 0 ] : null;

or however else you'd prefer.

Currently at work so can make a basic PR Request later fixing this issue.

Edit: Information

SQLSRV: 5.9.0+14116
PHP: 7.4.15 (NTS)
Nami: 5.7.2 (recent update from 5.3.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions