
PHP 7 Virtual Machine - lvht
http://nikic.github.io/2017/04/14/PHP-7-Virtual-machine.html
======
donatj
It's always pleasant to see PHP occasionally get a positive moment in the
limelight on HN. It's oft scorned yet powers a very large chunk of the web.
With the work done on 7 it's also one of the fastest scripting languages
around and deserves a little more credit if I'm honest.

~~~
malza
Honestly. I think its main problem is it's not hipster enough. It's too
popular. I bet if you made it difficult to use (for most people), added
features that make certain aspects a nightmare to scale and gave it a weird
name then it would do well here. Obviously don't let anyone know about the
origin... say you built it at a series of obscure coding bootcamps.

~~~
simias
I think that's unfair, the reason PHP has a bad reputation is not because of
silly hipsters. It's because for a long time it was a terribly designed
language. It was a laughing stock for a good reason. The whole "hobby-grade
templating language turned general purpose with complete disregard to how
programing languages are designed" thing.

Now I'm willing to believe that it's improved a lot since then, but it's got a
very bad reputation to overcome, and it's deserved. The languages seems headed
in the right direction at least, maybe in a few years we'll forget what PHP
used to be.

~~~
drspacemonkey
I'm pretty sure a substantial part of PHP's reputation is the nightmare code
produced by PHP developers.

~~~
cr0sh
And that goes right into the whole "badly designed language" trope as well.
Essentially, anything written in PHP prior to version 5 (and especially prior
to version 4) should be considered suspect.

I'm a long time PHP developer (well, was until recently - my current position
is in the javascript/nodejs stack arena), and have been using it since the v3
days (so not there from the beginning, but close enough). There were some
truly awful examples and code practices out there.

That isn't to say you couldn't write quality procedural PHP back in the day
(had you configured your server properly and stuck with "best practices") -
it's just that the majority of people hacking on PHP didn't. I'm sure there
were a few that did, though - but I'm hard-pressed to recall any at the
moment.

Today's PHP is a much different beast than yesterday's. The OOP model and
other advancements makes things so much better, provided they are all used
properly and followed. Now - could you make PHP 7 as ugly as 3? Sure. But
you'd be insane to do so unless you had no other choice...

~~~
drspacemonkey
Nail, meet hammer with claws on both sides.

It's entirely, 100% possible to write good, clean, tested, maintainable code
in PHP. But most people working with PHP, for whatever reason (and I'm sure
there are many reasons), simply don't bother.

I suppose the same can be said of all languages, but PHP devs are the worst
offenders IME.

------
tyingq
It's fairly impressive that the php7 core team was able to release something
that competes well with HHVM from a performance perspective.

I assume they are working with significantly fewer advantages and resources
than Facebook, so that's a pretty nice result.

~~~
nodesocket
HHVM was released in 2011, while PHP 7 was released in 2015. So perhaps in
that extra time there was additional techniques, optimizations, and technology
that allowed PHP 7 to stay comparable in terms of performance to HHVM.

~~~
tyingq
There was a long time to catch up, yes. But HHVM did several big improvements
to their JIT tech between then and now.

PHP7 also rolled out with very little noise about stability, migration issues,
etc.

Not knocking FB at all, just noting the PHP folks did a nice job.

~~~
kijin
The PHP team is absolutely obsessed with backward compatibility. They broke
surprisingly few things with PHP 7, and everything they broke was clearly
documented.

You don't get to power a significant fraction of the world's most important
websites if you break backward compatibility every few months.

~~~
bpicolo
They broke an unusual number of things in 7.1, a couple somewhat annoying e.g.
defaulting DateTime('now') to including microseconds, without a single builtin
function available that can strip/change microseconds on a datetime.

~~~
captn3m0
Yes, but they decided to keep it to 7.1, not 7.0, which meant the majority of
the perf upgrades were available to most users who migrated to 7.0 _easily_.

7.1 was where all the breaking changes got pushed as a result.

------
chx
Another one of nikic's seminal guides into the workings of PHP. It was him who
wrote the foreach guide on StackOverflow
[http://stackoverflow.com/a/14854568/308851](http://stackoverflow.com/a/14854568/308851)
.

Another note: if I ever catch you using these cute "finally ... interesting
edge-cases" described in this article, your PR will be refused. Yes, yes, it's
very smart, and you might win an obfuscation contest but in a professional
environment we like code that can be understood even when the emergency phone
kicks us out of bed. If it's five times as long, I care not, but if it
requires me to think hard on the code, I do.

------
_RPM
Great write up. Thank you for writing this. I've always been interested in the
PHP VM, but it is not documented. Nikic is one smart dude.

------
Vogtinator
That the smart branches optimization requires a workaround in the IR codegen
concerns me a bit. It makes sense in a HW context, like MIPS branch delay
slots, but not really here. There could be a flag in the branch instruction
that disables the optimization at least.

------
DenisM
I wonder if it's possible to compile it for iOS?

I need a templating engine in my app, and php seems like the most popular one.

~~~
improv32
PHP is a whole lot more than just a templating engine. I think you would find
that much more effort than is required just to make some templates.

~~~
DenisM
Perhaps you can send me down the righ path?

I want my users to be able to send emails from their iPads, and those emails
would be generated based on templates. There will be many such templates built
in, and eventually users will be able to hire web developer-type person to
make custom templates.

My thinking was that PHP is the most popular language for that sort of thing,
so it would be nice if could support that. My second choice is handlebars. I'm
not sure if JSX would do the job?

Any thoughts appreciated.

~~~
my_ghola
PHP is not a templating language. You can build a template engine with it, but
then, you can build one with any other language.

If your app is in swift or objective-c, look into template libraries for those
languages. Simple Google search tells me there's a couple of options including
one using handlebar's format.

~~~
DenisM
How is this not a template? It generates valId HTML out of data.

    
    
      <?php 
      for ($x = 0; $x <= 10; $x++) {
        echo "The number is: $x   <br>";
      } 

?>

