|| at Mar 21, 2015 at 4:10 pm
On 03/20/2015 04:54 PM, Marco Perone wrote:
From what I understand, PHP does not have tail call optimization.
I would like to ask if there is a reason for this. Is it because this
limitation comes from the C language? Is it a feature that was never
proposed? Is it a technical reason or a "human" one, or is it just
that there is no real reason and nobody ever really needed this?
Until very recently the way the engine was written made it prohibitively
difficult and costly to do. Prior to PHP 5.5, having no opcode cache was
the norm so compile time needed to be kept to an absolute minimum.
That's not the case anymore. Also, PHP 5 has no AST. PHP 7 does have
an AST, which means it should be possible to add compile-time
optimizations like tail recursion optimization.
That's not planned for PHP 7.0, but I believe people are discussing the
potential of it in 7.1 or 7.2. Stay tuned, or if you know C help out. :-)