Processing include/require directives in PHP

前端 未结 5 1517
广开言路
广开言路 2021-01-24 13:45

Background: I\'m building an automated test framework for a PHP application, and I need a way to efficiently \"stub out\" classes which encapsulate communicatio

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-24 14:10

    This is the closest thing I could find in the manual:

    If there are functions defined in the included file, they can be used in the main file independent if they are before return() or after. If the file is included twice, PHP 5 issues fatal error because functions were already declared, while PHP 4 doesn't complain about functions defined after return().

    And this is true regarding functions. If you define the same function in A and Z (after the return) with PHP 5, you'll get a fatal error as you expect.

    However, classes seem to fall back to PHP 4 behavior, where it doesn't complain about functions defined after return. To me this seems like a bug, but I don't see where the documentation says what should happen with classes.

提交回复
热议问题