Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/standard/file_get_contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function execute(Frame $frame): void
'file_get_contents() expects at least 1 argument, '.\max(0, $argc - 1).' given'
);
}
$filename = VmStreamPath::coerceNonEmptyPathArg(
$frame->calledArgs[0],
'file_get_contents',
$filename = VmStreamPath::coerceNonEmptyPathArgForFrame(
$frame,
0,
'file_get_contents',
'filename'
);
if (null === $frame->returnVar) {
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/file_put_contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function execute(Frame $frame): void
if (null === $frame->returnVar) {
return;
}
$path = VmFilestatArg::coerceFilenameArg($frame->calledArgs[0], 'file_put_contents');
$path = VmFilestatArg::filenameArgForFrame($frame, 0, 'file_put_contents');
$flags = 0;
if (isset($frame->calledArgs[2])) {
$flags = VmMath::parseIntBuiltinArgForFrame(
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/readfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function execute(Frame $frame): void
if (1 !== \count($frame->calledArgs)) {
throw new \LogicException('readfile() requires exactly one argument in this compiler build');
}
$path = VmStreamPath::coerceNonEmptyPathArg($frame->calledArgs[0], 'readfile');
$path = VmStreamPath::coerceNonEmptyPathArgForFrame($frame, 0, 'readfile', 'filename');
if (null === $frame->returnVar) {
return;
}
Expand Down
25 changes: 25 additions & 0 deletions test/compliance/cases/stdlib/file_io_null_strict_typeerror.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
stdlib file_get_contents/readfile/file_put_contents null under strict_types throws TypeError (#17063, ext/standard/file.c)
--FILE--
<?php
declare(strict_types=1);

foreach (['file_get_contents', 'readfile'] as $fn) {
try {
$fn(null);
echo $fn, ": uncaught\n";
} catch (TypeError $e) {
echo $fn, ': ', $e->getMessage(), "\n";
}
}

try {
file_put_contents(null, 'x');
echo "file_put_contents: uncaught\n";
} catch (TypeError $e) {
echo 'file_put_contents: ', $e->getMessage(), "\n";
}
--EXPECT--
file_get_contents: file_get_contents(): Argument #1 ($filename) must be of type string, null given
readfile: readfile(): Argument #1 ($filename) must be of type string, null given
file_put_contents: file_put_contents(): Argument #1 ($filename) must be of type string, null given
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
stdlib file_get_contents/readfile/file_put_contents null under strict_types JIT throws TypeError (#17063, ext/standard/file.c)
--FILE--
<?php
declare(strict_types=1);

foreach (['file_get_contents', 'readfile'] as $fn) {
try {
$fn(null);
echo $fn, ": uncaught\n";
} catch (TypeError $e) {
echo $fn, ': ', $e->getMessage(), "\n";
}
}

try {
file_put_contents(null, 'x');
echo "file_put_contents: uncaught\n";
} catch (TypeError $e) {
echo 'file_put_contents: ', $e->getMessage(), "\n";
}
--EXPECT--
file_get_contents: file_get_contents(): Argument #1 ($filename) must be of type string, null given
readfile: readfile(): Argument #1 ($filename) must be of type string, null given
file_put_contents: file_put_contents(): Argument #1 ($filename) must be of type string, null given
23 changes: 23 additions & 0 deletions test/repro/maintainer_gap_file_io_null_strict.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

// Maintainer gap #17063 — file I/O builtins null under strict_types must TypeError (ext/standard/file.c).
foreach (['file_get_contents', 'readfile'] as $fn) {
try {
$fn(null);
echo $fn, "=uncaught\n";
} catch (TypeError $e) {
echo $fn, '=TypeError', "\n";
} catch (Throwable $e) {
echo $fn, '=', get_class($e), "\n";
}
}

try {
file_put_contents(null, 'x');
echo "file_put_contents=uncaught\n";
} catch (TypeError $e) {
echo "file_put_contents=TypeError\n";
} catch (Throwable $e) {
echo 'file_put_contents=', get_class($e), "\n";
}