The PHP code base has grown over more than 2 decades, which leaves some room for code cleanups. While attempting to fix several crash bugs in the JIT, I found that PHP's C headers (*.h) and the existing #include directives are inconsistent, incomplete and bloated; many things just worked by chance, not by design, because there were a few headers which just included everything.
I wanted to help clean up this mess that had accumulated over two decades. After four PRs doing exactly that were widely welcomed and accepted, there was resistance from two individuals who demanded my changes to be reverted. This resistance surprised me, because I previously thought those code cleanups were common sense, and just nobody had so far taken the time to do it.
I propose an addition to PHP's coding standard describing how C headers and #includes should be managed:
(GitHub PR with the same contents: https://github.com/php/php-src/pull/10338)
Then, the reverted cleanups should be reconsidered:
I have already posted a new draft PR which contains all these, plus some more: https://github.com/php/php-src/pull/10345
Advantages of this proposal:
Disadvantages of this proposal:
Criticism issued on this proposal:
This proposal has no runtime effect. The PHP language is not affected, and the PHP executable will not change.
At the C source code level, reducing #includes may break the build of third-party extensions which forgot to include a header that was previously implied by PHP, e.g. “errno.h” is included for no reason, and extensions may rely on that.
If staying compatible with defective extensions is deemed important, these includes may be re-added to a header such as “php_compat.h”, possibly with a way to opt-out. That way, broken extensions still build, but PHP itself still benefits from a smaller and more correct set of #includes.
“master” branch (which may eventually become 8.3 or 9.0?).
No runtime impact.
The build of out-of-tree SAPIs may break for the same reasons as described above.
No runtime impact.
The build of out-of-tree extensiosn may break for the same reasons as described above.
No impact.
Being an in-tree extension, opcache benefits from those code cleanups. My PR contains cleanup commits for opcache.
Not applicable.
Not applicable.
The PHP language is completely unaffected.
Not applicable. This is an incremental improvement to PHP's source code.
Voting started on 2023-02-01 (two weeks after the RFC was posted to php-internals) and will end on 2023-02-15 at 15:00 UTC (another two weeks).
Primary vote:
Secondary (clarifications on how to clean up):
https://github.com/php/php-src/pull/10338 tracks the specification. https://github.com/php/php-src/pull/10345 tracks my proposed implementation.
https://github.com/php/php-src/pull/10410 is a PR splitted from https://github.com/php/php-src/pull/10345 with some minimal cleanup, as suggested on php-internals by Jakub Zelenka; it contains compatibility tweaks so (bad) third-party extensions do not break, such as always including errno.h from php.h
https://github.com/php/php-src/pull/10404 is a PR that adds a few third-party extensions to the CI; more extensions could easily be added. This is slighly out of this RFC's scope, but may help those who worry about extension breakages.
If voters decide that #include directives should not have code comments, then existing comments should be removed to reduce “clutter”; see https://github.com/php/php-src/pull/10472