PHP Sadness

Instanceof produces a syntax error on expressions

$ php -r '$a = get_class(new stdClass()); var_dump(new stdClass() instanceof $a);'
$ php -r 'var_dump(new stdClass() instanceof get_class(new stdClass());'
PHP Parse error:  syntax error, unexpected '(' in Command line code on line 1

php instanceof forces the right-hand-side value to be a literal variable or string, not an expression which evaluates to a string or object. As a runtime operator, there is no reason to restrict this behavior.

Significance: Chaining

The ability to chain function calls, array lookups, property accesses, and so on is important to being able to write clean, concise code. Requiring the developer to needlessly create extra temporary variables merely to pass a value from one language construct to another encourages lengthy, messy code which is costly to change and difficult to follow.

Significance: Implications for Internals

The mere presence of this issue tends to imply some fatal flaw or unnecessary complexity at the most basic levels of the language. For example, an overly complex parser might be trying to compensate for missing functionality in the interpreter by incorrectly (and misleadingly) validating code at the syntax level, or messages without details could indicate that the internal design prohibits access to values where they should be reachable in a sane implementation.