Neden PHP yuvalama fonksiyonları izin verecek?
<?php
function foo() {
function bar() {
return "bar";
}
return "foo";
}
print foo();
print bar();
.. Geçerli PHP.
Ancak:
- Neden yuvalama hiç ihtiyaç olurdu?
- Ve hatta eğer öyleyse, neden (sadece Withing foo (), ya da çukur foo.bar () veya örneğin, değil) her yerden çubuğunu çağırabilirsiniz.
I ran into this today, because I forgot a closing bracket somewhere, and had one too many further down. The code was valid and no errors thrown; but it all started acting really weird. Functions not being declared, callbacks going berserk and so on. Is this a feature, and if so, to what purpose? Or some idiosyncrasy?
ANSWER: commentor Bu duplicate What are php nested functions for sahip olduğunu işaret etmektedir.