Visitar URL original
JIT if condition optimization leads to flipped result: true is false and false is true · Issue #21593 · php/php-src · GitHub
Skip to content

JIT if condition optimization leads to flipped result: true is false and false is true #21593

Closed

Description

@paulmhh

Description

The following code:

<?php declare(strict_types=1);

$a = new stdClass();
$a->a = 'a';

if (!empty($a?->a)) {
    echo 'OK';
} else {
    echo 'ERROR';
}
echo PHP_EOL;

run with:
php -dopcache.enable=1 -dopcache.enable_cli=1 -dopcache.jit=1205 ./file.php
will result in
ERROR

while plain
php ./file.php
will result in
OK

tested with:

docker run --rm -ti -v ./jitIssue.php:/jitIssue.php php:8.5 php -dopcache.enable=1 -dopcache.enable_cli=1 -dopcache.jit=1205 /jitIssue.php
docker run --rm -ti -v ./jitIssue.php:/jitIssue.php php:8.4 php -dopcache.enable=1 -dopcache.enable_cli=1 -dopcache.jit=1205 /jitIssue.php

(it seems php8.3 is not affected)

The issue seems to be a negated empty with a null-safe operator inside, only in an if condition.
if (!empty($a?->a)) => fails
if (empty($a?->a)) => works
if (!empty($a->a)) => works
$result = !empty($a?->a) => works

PHP Version

PHP 8.4.19 (cli) (built: Mar 16 2026 22:25:56) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.19, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.19, Copyright (c), by Zend Technologies

and

PHP 8.5.4 (cli) (built: Mar 16 2026 22:25:19) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.4, Copyright (c), by Zend Technologies

Operating System

No response

Activity

  1. iluuu1994 commented on Apr 1, 2026

    @iluuu1994
    Member

    Nice reproducer, thanks!

  2. added a commit that references this issue on Apr 2, 2026
    455ae28
  3. paulmhh commented on Apr 2, 2026

    @paulmhh
    Author

    thank you for the very quick fix and the credits, much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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