PHP is still very Java-like in some ways though. Well... PHP likes to pretend it's a dynamic language (Closures, for instance), but at its core it's a very strange dynamic/static hybrid, utilising a single-pass compiler and with type checking done with syntax definitions(!)
Which is why this doesn't work: (actual intended production code)
self::$views[$path]();
Why? Because the syntax doesn't accomodate calling a closure that is an item in an array, which is a static member of a class.
> PHP likes to pretend it's a dynamic language (Closures, for instance),
PHP is a dynamic(ally typed) language, and closures have nothing to do with static/dynamic.
> at its core it's a very strange dynamic/static hybrid
No, at its core it's completely dynamically typed, it got static features when it decided to base its OO on Java's.
> Which is why this doesn't work:
This doesn't work because PHP uses a shitty ad-hoc parser for a shitty ad-hoc syntax, much like closures it's completely orthogonal to the language being dynamic or static.
Also, this piece of code doesn't involve any closure. It looks like you don't know what a closure is.
> PHP is still very Java-like in some ways though.
PHP has much more in common with Java/C# than Python and Ruby. If you took Java and added dynamic typing and compiled it fresh on each request you'd get something very close to PHP.
Just like how they added someFunc()[0] syntax recently I guess they will make these work one by one where the demand is by people wanting to use them. Granted it would be great if the compiler wasn't so brittle.
PHP's parser is the language syntax definition. It's perfectly reasonable for any PHP developer to attempt that call because it should work. PHP's parser, for no good reason, just doesn't like it. I'd consider it a bug rather than design problem.
Without having investigated it, I would guess that the parser isn't abstract and modular enough so they end up with a mess of code trying to handle all the different possible combinations of syntax.
Well... it parses, and after parsing each group of tokens runs a function. And yes, it replaces some bytecodes, but its lack of an AST means it can only post-process the bytecode.
And everyone I've spoken to refers to it as single-pass.
Post processing the bytecode is what makes it multi-pass. "One-pass" means that it literally makes one pass over the code. Whether it uses an AST or not isn't really relevant.
Which is why this doesn't work: (actual intended production code)
Why? Because the syntax doesn't accomodate calling a closure that is an item in an array, which is a static member of a class.But this works: