Skip to content

?? in if () statement misbehaving #20958

@bludwagon

Description

@bludwagon

Description

The following code:

<?php

$a=['t'=>'92345'];

var_dump($a['t']??0);// string(5) "92345"
var_dump('92345' < '12345');// false

if ($a['t']??0 < '12345'){echo('y');}else{echo('n');}// expected 'n' because ('92345' < '12345') <--- THIS
if ($a['x']??0 < '12345'){echo('y');}else{echo('n');}// expected 'y' because $a['x'] is null, so (0 < '12345')

Resulted in this output:

The ` <--- THIS` line returns 'y'

But I expected this output instead:

The ` <--- THIS` line returns 'n'

PHP Version

PHP 8.4.16 (cli) (built: Dec 18 2025 21:19:25) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies

Operating System

Debian

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions