Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ApeWare's avatar

PHP 7.1 "A non-numeric value encountered" on DB::raw

We have a query that is working fine on PHP7.0 and Laravel 5.1

->addSelect(DB::raw("CONCAT(IFNULL(creativeAirYear,'0000'),"-",IFNULL(creativeAirMonth,'00'),"-",IFNULL(creativeAirDay,'00')) as sortAirDate"))

When we deploy to our PHP 7.1 server we get a fatal error "A non-numeric value encountered"

If we change the raw query to:

->addSelect(DB::raw("CONCAT(IF(creativeAirYear IS NOT NULL, creativeAirYear,'0000'), '-',IF(creativeAirMonth IS NOT NULL, creativeAirMonth, '00'),'-', IF(creativeAirDay IS NOT NULL, creativeAirDay, '00')) AS sortAirDate"))

the error goes away and the query works fine.

At the end of the day, the CONCAT provides the same results but it seems unnecessarily verbose and I don't understand why it would cause an error.

I have done a significant amount of research but have come up empty in finding out why. Any ideas?

0 likes
5 replies
Mittensoff's avatar

Did you check the second query for the case where creativeAirMonth is null?

d3xt3r's avatar
d3xt3r
Best Answer
Level 29

Not sure, why it would work on one version. The placement of " does not seem correct in first query... either escape the double quotes or use single quotes ....

ApeWare's avatar

@Mittensoff that is what that CONCAT does, if it is not null, it uses the value, otherwise it will substitute a value. We may have any combination of Year, Month, Day so this creates a sort value. Just having this select in, caused the page to crash in PHP7.1; the refactored concat works just fine, even though it does the same thing in long form.

@dext3r that was a typo when I entered it into the forum post (corrected). Thanks!

ApeWare's avatar

@d3xt3r I took a second look and you were right, the double-quote I used to divide the Y-m-d seemed to fix the issue on the PHP7.1 server. Still strange that it didn't cause an issue on 7.0 nor in eloquent on Laravel 5.1.

I would have thought that it would have caused an error. Changing original post to reflect original code so these comments make sense to others.

Please or to participate in this conversation.