Fix broken assert(is_numeric($sql)) in DateAddFunction and DateSubFunction #7313

Closed
opened 2026-01-22 15:49:49 +01:00 by admin · 2 comments
Owner

Originally created by @ondrejmirtes on GitHub (Feb 9, 2024).

Bug Report

Q A
BC Break yes
Version 3.0

Summary

I'm working on ORM 3 and DBAL 4 support on phpstan-doctrine, and I have this test case:

				SELECT		DATE_ADD(m.datetimeColumn, m.intColumn, \'day\'),
							DATE_ADD(m.stringNullColumn, m.intColumn, \'day\'),
							DATE_ADD(m.datetimeColumn, NULLIF(m.intColumn, 1), \'day\'),
							DATE_ADD(\'2020-01-01\', 7, \'day\')
				FROM		QueryResult\Entities\Many m

Doctrine crashes on this line: 5a40b99e11/src/Query/AST/Functions/DateAddFunction.php (L74)

The $sql value is: m0_.intColumn.

I think the assert assumption is wrong, as interval does not have to refer to a scalar value, but can be a column as well. The job of this part of the codebase is to just generate the correct SQL query to execute against the database.

Same problem is in DateSubFunction too.

Current behavior

assert(): assert(is_numeric($sql)) failed

Expected behavior

It should work and generate the right SQL.

Originally created by @ondrejmirtes on GitHub (Feb 9, 2024). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | yes | Version | 3.0 #### Summary I'm working on ORM 3 and DBAL 4 support on phpstan-doctrine, and I have this test case: ```php SELECT DATE_ADD(m.datetimeColumn, m.intColumn, \'day\'), DATE_ADD(m.stringNullColumn, m.intColumn, \'day\'), DATE_ADD(m.datetimeColumn, NULLIF(m.intColumn, 1), \'day\'), DATE_ADD(\'2020-01-01\', 7, \'day\') FROM QueryResult\Entities\Many m ``` Doctrine crashes on this line: https://github.com/doctrine/orm/blob/5a40b99e11a0de532eb866f062dccad20da19add/src/Query/AST/Functions/DateAddFunction.php#L74 The `$sql` value is: `m0_.intColumn`. I think the `assert` assumption is wrong, as `interval` does not have to refer to a scalar value, but can be a column as well. The job of this part of the codebase is to just generate the correct SQL query to execute against the database. Same problem is in DateSubFunction too. #### Current behavior ``` assert(): assert(is_numeric($sql)) failed ``` #### Expected behavior <!-- What was the expected (correct) behavior? --> It should work and generate the right SQL.
admin added the Bug label 2026-01-22 15:49:49 +01:00
admin closed this issue 2026-01-22 15:49:49 +01:00
Author
Owner

@derrabus commented on GitHub (Feb 9, 2024):

That looks like a valid bug. PR welcome if someone wants to give it a try before I find the time.

@derrabus commented on GitHub (Feb 9, 2024): That looks like a valid bug. PR welcome if someone wants to give it a try before I find the time.
Author
Owner

@ondrejmirtes commented on GitHub (Feb 9, 2024):

I'm trying: https://github.com/doctrine/orm/pull/11243

@ondrejmirtes commented on GitHub (Feb 9, 2024): I'm trying: https://github.com/doctrine/orm/pull/11243
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7313