Does PHP optimize tail recursion?

后端 未结 3 1563
不知归路
不知归路 2020-12-03 02:58

I wrote a small piece of code that I believe should have succeeded if tail recursion was optimized, however it blew up the stack. Should I conclude PHP does not optimize tai

3条回答
  •  春和景丽
    2020-12-03 03:10

    It is important to know that PHP is a scripting language written in C so limitations of this sort are bound to appear. The lack of optimization shows in the underlying C language also:

    http://rosettacode.org/wiki/Find_limit_of_recursion

    As you can see PHP is not the only language that does not handle things gracefully.

    I recommend using Erlang and the MyPeb PHP/Erlang bridge for a true solution to a problem like this.

提交回复
热议问题