6 ms·
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 stra
by TazeTSchnitzel 14y ago
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.
But this works:
$x = self::$views[$path];
$x();
- agumonkey 14y agoI suspected a weird kind of type checking. It's so dynamic they're hitting walls whenever they want to improve things I guess. One PhD students tried to make a PHP compiler, hair loss ensued.
- masklinn 14y ago> 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.
- TazeTSchnitzel 14y ago>Also, this piece of code doesn't involve any closure. It looks like you don't know what a closure is. Yes it does, it executes what PHP calls a "Closure": http://php.net/manual/en/class.closure.php http://php.net/manual/en/class.closure.php
- deleted 14y ago[deleted]
- encoderer 14y agoActually, not really. Your code breaks on any PHP "callable" http://php.net/manual/en/language.types.callable.php http://php.net/manual/en/language.types.callable.php of which Closures are just one.
- TazeTSchnitzel 14y agoI'm well aware of that. Although it seems PHP tried to treat it as a string callable IIRC.
- wvenable 14y agoThere's no reason in PHP's design that wouldn't work -- they just need someone to work on improving the parser to handle that.
- TazeTSchnitzel 14y agoIt's not improving the parser, it's improving the language's syntax definition, which shouldn't care about this in the first place.
- wvenable 14y agoPHP'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.
- robryan 14y agoWithout 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.
- wvenable 14y ago> 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.
- TazeTSchnitzel 14y agoExactly.
- robryan 14y agoJust 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.
- pbiggar 14y agoAs a point of fact, it is not a single pass compiler.
- TazeTSchnitzel 14y agoIn what sense?
- pbiggar 14y agoHow many senses are there? It parses, then does "bytecode" generation, then fiddles with the bytecodes a bit. So it does multiple passes.
- TazeTSchnitzel 14y agoWell... 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.
- pbiggar 14y agoPost 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.