Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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();


> 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.


>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


Actually, not really.

Your code breaks on any PHP "callable" http://php.net/manual/en/language.types.callable.php of which Closures are just one.


I'm well aware of that.

Although it seems PHP tried to treat it as a string callable IIRC.


> 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.


Exactly.


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.


I 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.


I assure you, I still have all of my hair ;)


I meant mine obviously ;)

For the curious, here's the talk (1 hour) about ahead of time compilation of PHP:

http://www.youtube.com/watch?v=kKySEUrP7LA


What's the link to your research?


I was trying to be funny, insinuating your talk was so extensive that my hair fell.


There's no reason in PHP's design that wouldn't work -- they just need someone to work on improving the parser to handle that.


It's not improving the parser, it's improving the language's syntax definition, which shouldn't care about this in the first place.


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.


As a point of fact, it is not a single pass compiler.


In what sense?


How many senses are there?

It parses, then does "bytecode" generation, then fiddles with the bytecodes a bit. So it does multiple passes.


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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: