Object of class %s could not be converted to bool

Description

PHP reports that the object cannot be used as a boolean. Converting an object into a boolean is a PHP engine feature, and should be always on. Though, some extensions have not systematically implemented it.

Here, gmp is lacking the support for converting objects into a boolean, though it was fixed in PHP 8.4. When meeting such error, it should be reported to the author of the extension.

Example

<?php

$x = gmp_result('12', 3);

if ($x) {
    print $x is truthy;
}

?>

Literal Examples

  • Object of class GMP could not be converted to bool

Solutions

  • Make an explicit comparison, with is_object().

  • Make an explicit comparison, with instanceof.