Skip to content

Phar does not respect case-insensitiveness of __halt_compiler() when reading stub #20442

@shyim

Description

@shyim

Description

The following code:

stub.php

<?php

echo "Hello World!";

__halt_compiler();

build.php

<?php

$phar = new Phar('output.phar');
$phar->startBuffering();

$phar->setStub(file_get_contents('stub.php'));
$phar->addEmptyDir('src');

$phar->stopBuffering();

Resulted in this output:

~/Downloads/foo via 🐘 v8.4.14
❯ php -dphar.readonly=0 build.php

~/Downloads/foo via 🐘 v8.4.14
❯ php -dphar.readonly=0 build.php
PHP Fatal error:  Uncaught UnexpectedValueException: internal corruption of phar "/Users/shyim/Downloads/foo/output.phar" (__HALT_COMPILER(); not found) in /Users/shyim/Downloads/foo/build.php:3
Stack trace:
#0 /Users/shyim/Downloads/foo/build.php(3): Phar->__construct('output.phar')
#1 {main}
  thrown in /Users/shyim/Downloads/foo/build.php on line 3

Fatal error: Uncaught UnexpectedValueException: internal corruption of phar "/Users/shyim/Downloads/foo/output.phar" (__HALT_COMPILER(); not found) in /Users/shyim/Downloads/foo/build.php:3
Stack trace:
#0 /Users/shyim/Downloads/foo/build.php(3): Phar->__construct('output.phar')
#1 {main}
  thrown in /Users/shyim/Downloads/foo/build.php on line 3

But when I write __HALT_COMPILER in UPPER case it works always. I normally write it always upper-case but saw in docs other mentioned, just copy pasted. https://www.php.net/manual/en/function.halt-compiler.php

it looks like it's hard-code to upper-case:

static const char halt_stub[] = "__HALT_COMPILER();";

Are the docs just wrong, should this be changed in php idk 😂 . The execution of the phar works with regardless of caseing

PHP Version

PHP 8.4.14 (cli) (built: Oct 21 2025 19:23:55) (NTS)
Copyright (c) The PHP Group
Built by Shivam Mathur
Zend Engine v4.4.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.14, Copyright (c), by Zend Technologies

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions