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
9 changes: 5 additions & 4 deletions ext/spl/MultipleIteratorBuiltin.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,13 @@ public function execute(Frame $frame): void
MultipleIteratorBuiltin::CLASS_LC,
'MultipleIterator::setFlags()'
);
// php-src zim_MultipleIterator_setFlags — ZEND_PARSE_PARAMETERS_ARGS(1, 1)
// php-src zim_MultipleIterator_setFlags — ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG (#31795).
$this->requireExactUserArgCount($frame, 'MultipleIterator::setFlags', 1);
$flags = VmMath::parseIntBuiltinArg(
$frame->calledArgs[1],
$flags = VmMath::parseZParamLongBuiltinArgForFrame(
$frame,
1,
'MultipleIterator::setFlags',
0,
1,
'flags'
);
MultipleIteratorBuiltin::setFlags($object, $flags);
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<file>./test/compliance/DirectoryIteratorNullPath31512VMTest.php</file>
<file>./test/compliance/SplDllistOutOfRangeExceptionClass31553VMTest.php</file>
<file>./test/compliance/MultipleIteratorKeyDuplication31552VMTest.php</file>
<file>./test/compliance/MultipleIteratorSetFlagsNullSoft31795VMTest.php</file>
<file>./test/compliance/CachingIteratorMultiToStringFlags31551VMTest.php</file>
<file>./test/compliance/CachingIteratorOffsetGetMissingKeyWarn31576VMTest.php</file>
<file>./test/compliance/DateIntervalCreateFromDateStringBadTokenWarn31575VMTest.php</file>
Expand Down
20 changes: 20 additions & 0 deletions test/compliance/MultipleIteratorSetFlagsNullSoft31795VMTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

require_once __DIR__.'/../BaseTest.php';

/** Focused VM PHPT for MultipleIterator::setFlags(null) soft-null (#31795). */
final class MultipleIteratorSetFlagsNullSoft31795VMTest extends BaseTest
{
protected string $BIN = __DIR__.'/../../bin/vm.php';

public static function providePHPTests(): \Generator
{
$path = __DIR__.'/cases/spl/multipleiterator_setflags_null_soft.phpt';
[$name, $code, $sections] = self::parsePHPT($path, 'multipleiterator_setflags_null_soft');
yield $name => [$name, $code, $sections];
}
}
25 changes: 25 additions & 0 deletions test/compliance/cases/spl/multipleiterator_setflags_null_soft.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
MultipleIterator::setFlags(null) — soft-null DEP cites parameter #1 (#31795)
--FILE--
<?php
error_reporting(E_ALL);
set_error_handler(static function (int $no, string $msg): bool {
if (E_DEPRECATED === $no) {
echo "DEP:{$msg}\n";
return true;
}
echo "E{$no}:{$msg}\n";
return true;
});
$m = new MultipleIterator();
$m->attachIterator(new ArrayIterator([1]));
try {
$m->setFlags(null);
echo 'flags=' . $m->getFlags() . "\n";
} catch (Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage() . "\n";
}
?>
--EXPECT--
DEP:MultipleIterator::setFlags(): Passing null to parameter #1 ($flags) of type int is deprecated
flags=0
23 changes: 23 additions & 0 deletions test/repro/maintainer_gap_multipleiterator_setflags_null.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Maintainer gap: MultipleIterator::setFlags(null).
* Zend: E_DEPRECATED parameter #1 ($flags) + soft-coerce to 0
* VM: E_DEPRECATED parameter #0 ($flags) (wrong user arg index)
*/
error_reporting(E_ALL);
set_error_handler(static function (int $no, string $msg): bool {
if (E_DEPRECATED === $no) {
echo "DEP:{$msg}\n";
return true;
}
echo "E{$no}:{$msg}\n";
return true;
});
$m = new MultipleIterator();
$m->attachIterator(new ArrayIterator([1]));
try {
$m->setFlags(null);
echo 'flags=' . $m->getFlags() . "\n";
} catch (Throwable $e) {
echo get_class($e) . ':' . $e->getMessage() . "\n";
}
25 changes: 25 additions & 0 deletions test/repro/maintainer_gap_splfileobject_setflags_null.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Maintainer gap: SplFileObject::setFlags(null).
* Zend: E_DEPRECATED + soft-coerce to 0
* VM: silent coerce to 0 (no E_DEPRECATED)
*/
error_reporting(E_ALL);
set_error_handler(static function (int $no, string $msg): bool {
if (E_DEPRECATED === $no) {
echo "DEP:{$msg}\n";
return true;
}
echo "E{$no}:{$msg}\n";
return true;
});
$tmp = tempnam(sys_get_temp_dir(), 'sfo317');
file_put_contents($tmp, "a\nb\n");
try {
$f = new SplFileObject($tmp);
$f->setFlags(null);
echo 'flags=' . $f->getFlags() . "\n";
} catch (Throwable $e) {
echo get_class($e) . ':' . $e->getMessage() . "\n";
}
@unlink($tmp);
111 changes: 111 additions & 0 deletions test/unit/Issue31795MultipleIteratorSetFlagsNullTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

use PHPUnit\Framework\TestCase;

/**
* MultipleIterator::setFlags(null) — soft-null E_DEPRECATED cites parameter #1 (#31795).
*
* php-src: ext/spl/spl_iterators.c — zim_MultipleIterator_setFlags
*/
final class Issue31795MultipleIteratorSetFlagsNullTest extends TestCase
{
public function testVmSetFlagsNullDeprecationCitesParameterOne(): void
{
$out = $this->runBin('bin/vm.php', $this->softProbeCode());
$this->assertSame($this->expectedSoftOutput(), $out);
}

public function testJitSetFlagsNullDeprecationCitesParameterOne(): void
{
$out = $this->runBin('bin/jit.php', $this->softProbeCode());
$this->assertSame($this->expectedSoftOutput(), $out);
}

public function testVmStrictTypesSetFlagsNullTypeError(): void
{
$out = $this->runBin('bin/vm.php', $this->strictProbeCode());
$this->assertSame(
"TypeError: MultipleIterator::setFlags(): Argument #1 (\$flags) must be of type int, null given\n",
$out
);
}

private function expectedSoftOutput(): string
{
return "DEP:MultipleIterator::setFlags(): Passing null to parameter #1 (\$flags) of type int is deprecated\n"
."flags=0\n";
}

private function softProbeCode(): string
{
return <<<'PHP'
<?php
error_reporting(E_ALL);
set_error_handler(static function (int $no, string $msg): bool {
if (E_DEPRECATED === $no) {
echo "DEP:{$msg}\n";
return true;
}
echo "E{$no}:{$msg}\n";
return true;
});
$m = new MultipleIterator();
$m->attachIterator(new ArrayIterator([1]));
try {
$m->setFlags(null);
echo 'flags=' . $m->getFlags() . "\n";
} catch (Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage() . "\n";
}
PHP;
}

private function strictProbeCode(): string
{
return <<<'PHP'
<?php
declare(strict_types=1);
error_reporting(E_ALL);
$m = new MultipleIterator();
$m->attachIterator(new ArrayIterator([1]));
try {
$m->setFlags(null);
echo "ok\n";
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
PHP;
}

private function runBin(string $bin, string $code): string
{
$repo = dirname(__DIR__, 2);
$tmp = tempnam(sys_get_temp_dir(), 'phpc_31795_');
$this->assertNotFalse($tmp);
file_put_contents($tmp, $code);
$env = $_ENV;
LlvmToolchain::applyProcessEnv($env, $repo);
$proc = proc_open(
['php', $repo.'/'.$bin, $tmp],
[0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
$pipes,
$repo,
$env
);
$this->assertIsResource($proc);
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$exit = proc_close($proc);
@unlink($tmp);
$this->assertSame(0, $exit, $stdout.$stderr);

return $stdout;
}
}
Loading