Skip to content

AST pretty-printing drops meaningful parentheses around RHS of instanceof #22387

@TimWolla

Description

@TimWolla

Description

The following code:

<?php

$foo = new stdClass();
const bar = 'stdClass';

try {
	assert(!$foo instanceof (bar));
} catch (AssertionError $e) {
	echo $e->getMessage(), PHP_EOL;
}

Resulted in this output:

assert(!$foo instanceof bar)

But I expected this output instead:

assert(!$foo instanceof (bar))

PHP Version

PHP 8.6.0-dev (cli) (built: Jun 21 2026 18:51:23) (ZTS DEBUG)
Copyright © The PHP Group and Contributors
Zend Engine v4.6.0-dev, Copyright © Zend by Perforce
    with Zend OPcache v8.6.0-dev, Copyright ©, by Zend by Perforce

Operating System

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions