Am 27.05.2026 um 15:19 schrieb Ben Ramsey ramsey@php.net:
The problem with assigning meaning to a file extension is that the
interpreter (currently) doesn't care what the file extension is. As long
as it's text, it'll process any file and execute what comes after any
<?php tags.Right, that is the current behavior, and changing it is exactly what the proposal is about. The engine would learn to check the file extension at the entry point (zend_compile_file for SAPI/CLI, and the include/require family for nested loads) and use that to set the initial lexer state. The .php behavior remains untouched.
The behavior right now is that the file extension isn't checked. So,
whether it's .php, .phtml, .php3, .rb, .py, or .txt doesn't matter.
Using .php is a convention, not a requirement. If the proposal places
any restrictions on the file extension, that's a major BC break.
So, the logic will need to be something like: if .phpc, then parse
assuming there are no <?php tags, otherwise assume there must be <?php tags.
That said, you point indirectly at something I do need to address: there are entry paths where the engine does not have a filename, or has one it should not trust. Off the top of my head:
- stdin (cat foo.phpc | php). No filename available. Options: require an explicit CLI flag (php --pure), or simply not support this path and document it.
- eval(). Operates on strings, not files. Extension is irrelevant here; eval() continues to require <?php as today.
- Phar archives. Internal entries have filenames, so dispatch by extension should work, but I would need to verify.
- include of a URL stream (rare, often disabled). Same question. Probably handled by extension on the URL path.
I will work these out explicitly in the RFC draft. Thanks for surfacing it.
At the risk of bike-shedding, I think it could be easy for others to
confuse .phpc files as byte-code files, since it's common to see Python
byte-code files with the .pyc extension.Fair point, and one I had not weighed heavily enough. The Python .pyc parallel is real and would cause exactly the kind of one-time confusion that adds friction to adoption. Boutell's 2012 RFC used .phpp (Pure PHP) for the same purpose, which avoids the bytecode association. I am open to .phpp or other suggestions; the disambiguator matters less than the mechanism.
I'm still unsure about assigning any meaning to the extension. Maybe
this is something that could be handled at the SAPI configuration level
similar to how .phps files are configured? Likewise, maybe the CLI
should have a -p flag that tells it to process the input without
checking for <?php tags.
For what it's worth, php foo.phps still executes the file. You need to
run php -s foo.phps to output HTML syntax-highlighted source. The
.phps extension has no meaning to the interpreter.
That said, I'm not sure how you'd handle this with include/require or in
Phar files.
Cheers,
Ben