Category
stdlib · php-src-strict
Problem
file_get_contents($path, false, null, $offset, $length) must return a substring of the file bytes starting at $offset for at most $length bytes. Zend returns the slice on readable local files; this compiler returns false for the 5-argument form even when the path is valid and readable.
Single-argument and no-offset forms work; failure is specific to $offset + $length operands.
php-src reference
Repro (failure today — verified 2026-06-19)
test/repro/maintainer_file_get_contents_offset.php (or inline):
<?php
declare(strict_types=1);
$slice = file_get_contents(__FILE__, false, null, 0, 10);
var_export($slice);
echo "\n";
$mid = file_get_contents(__FILE__, false, null, 5, 5);
var_export($mid);
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_file_get_contents_offset.php
php bin/vm.php test/repro/maintainer_file_get_contents_offset.php
'
| Probe |
Zend PHP 8.2 |
VM today |
file_get_contents(__FILE__, false, null, 0, 10) |
first 10 bytes (e.g. '<?php\nvar_') |
false ❌ |
file_get_contents(__FILE__, false, null, 5, 5) |
5-byte mid slice |
false ❌ |
file_get_contents(__FILE__) |
full file |
OK |
Scope (PHP-in-PHP first)
| Path |
Work |
ext/standard/file_get_contents.php |
Honor $offset + $length in PHP read helper |
ext/standard/VmFs.php / stream read |
Seek + bounded read; reject only on real I/O failure |
lib/JIT/Builtin/FileGetContents.php |
Mirror slice semantics or defer with matrix note |
| Tests |
test/compliance/cases/stdlib/file_get_contents_offset_length.phpt |
Forbidden: new slice logic in runtime/*.c — port php-src behavior into ext/standard.
Done when (php-src-strict)
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter file_get_contents_offset 2>/dev/null || true'
Related
Category
stdlib· php-src-strictProblem
file_get_contents($path, false, null, $offset, $length)must return a substring of the file bytes starting at$offsetfor at most$lengthbytes. Zend returns the slice on readable local files; this compiler returnsfalsefor the 5-argument form even when the path is valid and readable.Single-argument and no-offset forms work; failure is specific to
$offset+$lengthoperands.php-src reference
ext/standard/file.c—PHP_FUNCTION(file_get_contents)(offset,maxlen/$length)ext/standard/streams.c— stream read with offsetRepro (failure today — verified 2026-06-19)
test/repro/maintainer_file_get_contents_offset.php(or inline):file_get_contents(__FILE__, false, null, 0, 10)'<?php\nvar_')false❌file_get_contents(__FILE__, false, null, 5, 5)false❌file_get_contents(__FILE__)Scope (PHP-in-PHP first)
ext/standard/file_get_contents.php$offset+$lengthin PHP read helperext/standard/VmFs.php/ stream readlib/JIT/Builtin/FileGetContents.phptest/compliance/cases/stdlib/file_get_contents_offset_length.phptForbidden: new slice logic in
runtime/*.c— port php-src behavior intoext/standard.Done when (php-src-strict)
$offsetbeyond file length →false/ empty string per Zend (document which)file_get_contents()with stream context + offset still works./script/ci-fast.sh --filter file_get_contents_offsetgreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter file_get_contents_offset 2>/dev/null || true'Related
filename:param · Stdlib: stream_context_set_options() inline array literal — $options arrives null (ext/standard/streams.c) #10056 stream_context inline literal · Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492