Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Strings Are Bigger Than Integers

When comparing strings and integers with inequalities (<, =<, >, >=), strings used to be smaller than numbers and they are bigger than numbers in PHP 8.0. Unless, they can be converted to integer safely.

PHP code

<?php

var_dump('a' > -1);
var_dump('a' > 0);
var_dump('a' > 1);

var_dump('a' < -1);
var_dump('a' < 0);
var_dump('a' < 1);

?>

Before

bool(true)
bool(false)
bool(false)

bool(false)
bool(false)
bool(true)

After

bool(true)
bool(true)
bool(true)

bool(false)
bool(false)
bool(false)

PHP version change

This behavior changed in 8.0.

See Also

© 2023-2026, Damien Seguy - Exakat