Skip to content

Conversation

@wera-as
Copy link

@wera-as wera-as commented Aug 29, 2023

Fixes this error: PHP Fatal error: Uncaught TypeError: mktime(): Argument #6 ($year) must be of type ?int, string given in /wp-includes/class-wp-date-query.php:320

Trac ticket: https://core.trac.wordpress.org/ticket/59235

*/
if ( is_array( $date_query['year'] ) ) {
$_year = reset( $date_query['year'] );
$_year = intval(reset( $date_query['year'] ));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$_year = intval(reset( $date_query['year'] ));
$_year = intval( reset( $date_query['year'] ) );

*/
if ( is_array( $date_query['year'] ) ) {
$_year = reset( $date_query['year'] );
$_year = intval( reset( $date_query['year'] )) ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$_year = intval( reset( $date_query['year'] )) ;
$_year = intval( reset( $date_query['year'] ) );

$_year = intval( reset( $date_query['year'] )) ;
} else {
$_year = $date_query['year'];
$_year = intval( $date_query['year']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$_year = intval( $date_query['year']);
$_year = intval( $date_query['year'] );

*/
if ( is_array( $date_query['year'] ) ) {
$_year = reset( $date_query['year'] );
$_year = intval( reset( $date_query['year'] )) ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset() can return false. I think the condition wrapping this should probably be adjusted to also check for a non-empty array to avoid this.

Also, please do not use intval() except as a callback. A simple (int) cast is better.

$_year = intval( reset( $date_query['year'] )) ;
} else {
$_year = $date_query['year'];
$_year = intval( $date_query['year']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing: please use (int) instead of intval().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants