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
32 changes: 27 additions & 5 deletions ext/standard/substr_compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use PHPCompiler\JIT\Builtin\StringSubstrCompare;
use PHPCompiler\JIT\Builtin\TypeErrorRaise;
use PHPCompiler\JIT\Context;
use PHPCompiler\JIT\ExceptionBridge;
use PHPCompiler\JIT\JitBoolArg;
use PHPCompiler\JIT\JitOperandTypeLabel;
use PHPCompiler\JIT\JitStringArg;
use PHPCompiler\JIT\JitStringBuiltinArg;
Expand Down Expand Up @@ -48,10 +50,16 @@ public function execute(Frame $frame): void
$length = self::requireIntArg($frame->calledArgs[3], 'substr_compare', 4, 'length');
}
}
// Z_PARAM_BOOL $case_insensitive — strict TypeError; soft-null DEP+coerce (#29756).
$caseInsensitive = false;
if (5 === $argc) {
$ci = $frame->calledArgs[4]->resolveIndirect();
$caseInsensitive = $ci->toBool();
$caseInsensitive = VmMath::parseBoolBuiltinArgForFrame(
$frame,
4,
'substr_compare',
5,
'case_insensitive'
);
}
if (null === $frame->returnVar) {
return;
Expand Down Expand Up @@ -105,13 +113,27 @@ public function call(Context $context, JITVariable ...$args): Value
$lengthVal = self::lowerStrictIntArg($context, $args[3], 'substr_compare', 4, 'length');
}
}
// Z_PARAM_BOOL $case_insensitive — strict TypeError; soft-null DEP+coerce (#29756).
// Compile-time null under strict: emit catchable TypeError and stop (do not continue
// after terminator — lowerCoerceZParamBool would soft-null-DEP into a dead block).
$ci = $i32->constInt(0, false);
if (5 === $argc) {
if (JITVariable::TYPE_NATIVE_BOOL !== $args[4]->type) {
throw new \LogicException('substr_compare() case_insensitive must be a boolean in this compiler build');
if ($context->callerStrictTypes && self::isCompileTimeNull($args[4])) {
ExceptionBridge::emitTypeErrorAndAbort(
$context,
'substr_compare(): Argument #5 ($case_insensitive) must be of type bool, null given'
);

return $i64->constInt(0, false);
}
$ci = $context->builder->zExt(
$this->jitBool($context, $args[4], 'substr_compare() case_insensitive'),
JitBoolArg::lowerCoerceZParamBool(
$context,
$args[4],
'substr_compare',
'case_insensitive',
5
),
$i32
);
}
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@
<file>./test/compliance/RoundNullModeForward84JITTest.php</file>
<file>./test/compliance/SubstrCompareNullOffsetVMTest.php</file>
<file>./test/compliance/SubstrCompareNullOffsetJITTest.php</file>
<file>./test/compliance/SubstrCompareNullCiStrictVMTest.php</file>
<file>./test/compliance/SubstrCompareNullCiStrictJITTest.php</file>
<file>./test/compliance/SubstrCompareNullCiCoerceVMTest.php</file>
<file>./test/compliance/SubstrCompareNullCiCoerceJITTest.php</file>
<file>./test/compliance/MetaphoneMaxPhonemesValueErrorVMTest.php</file>
<file>./test/compliance/MetaphoneMaxPhonemesValueErrorJITTest.php</file>
<file>./test/compliance/FilePutContentsEmptyPathValueErrorVMTest.php</file>
Expand Down
29 changes: 29 additions & 0 deletions test/compliance/SubstrCompareNullCiCoerceJITTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

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

/**
* @group llvm
*/
/** JIT: substr_compare(null $case_insensitive) soft-null DEP+coerce (#29756). */
final class SubstrCompareNullCiCoerceJITTest extends BaseTest
{
protected static string $DIR = __DIR__;

public static function providePHPTests(): \Generator
{
yield 'substr_compare_null_ci_coerce_jit.phpt' => self::parsePHPT(
__DIR__.'/cases/stdlib/substr_compare_null_ci_coerce_jit.phpt',
'substr_compare_null_ci_coerce_jit.phpt'
);
}

public function setUp(): void
{
$this->BIN = realpath(__DIR__.'/../../bin/jit.php');
}
}
26 changes: 26 additions & 0 deletions test/compliance/SubstrCompareNullCiCoerceVMTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

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

/** VM: substr_compare(null $case_insensitive) soft-null DEP+coerce (#29756). */
final class SubstrCompareNullCiCoerceVMTest extends BaseTest
{
protected static string $DIR = __DIR__;

public static function providePHPTests(): \Generator
{
yield 'substr_compare_null_ci_coerce.phpt' => self::parsePHPT(
__DIR__.'/cases/stdlib/substr_compare_null_ci_coerce.phpt',
'substr_compare_null_ci_coerce.phpt'
);
}

public function setUp(): void
{
$this->BIN = realpath(__DIR__.'/../../bin/vm.php');
}
}
29 changes: 29 additions & 0 deletions test/compliance/SubstrCompareNullCiStrictJITTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

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

/**
* @group llvm
*/
/** JIT: substr_compare(null $case_insensitive) under strict_types TypeError (#29756). */
final class SubstrCompareNullCiStrictJITTest extends BaseTest
{
protected static string $DIR = __DIR__;

public static function providePHPTests(): \Generator
{
yield 'substr_compare_null_ci_strict_jit.phpt' => self::parsePHPT(
__DIR__.'/cases/stdlib/substr_compare_null_ci_strict_jit.phpt',
'substr_compare_null_ci_strict_jit.phpt'
);
}

public function setUp(): void
{
$this->BIN = realpath(__DIR__.'/../../bin/jit.php');
}
}
26 changes: 26 additions & 0 deletions test/compliance/SubstrCompareNullCiStrictVMTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

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

/** VM: substr_compare(null $case_insensitive) under strict_types TypeError (#29756). */
final class SubstrCompareNullCiStrictVMTest extends BaseTest
{
protected static string $DIR = __DIR__;

public static function providePHPTests(): \Generator
{
yield 'substr_compare_null_ci_strict.phpt' => self::parsePHPT(
__DIR__.'/cases/stdlib/substr_compare_null_ci_strict.phpt',
'substr_compare_null_ci_strict.phpt'
);
}

public function setUp(): void
{
$this->BIN = realpath(__DIR__.'/../../bin/vm.php');
}
}
23 changes: 23 additions & 0 deletions test/compliance/cases/stdlib/substr_compare_null_ci_coerce.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
stdlib substr_compare(null $case_insensitive) soft-null DEP+coerce (#29756, ext/standard/string.c Z_PARAM_BOOL)
--FILE--
<?php
set_error_handler(static function (int $no, string $msg): bool {
if (E_DEPRECATED === $no) {
echo "DEP\n";

return true;
}

return false;
});
try {
$r = substr_compare('abc', 'ab', 0, 2, null);
echo (0 === $r ? 'OK' : 'BAD '.var_export($r, true)), "\n";
} catch (Throwable $e) {
echo get_class($e), ':', $e->getMessage(), "\n";
}
?>
--EXPECT--
DEP
OK
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
JIT: substr_compare(null $case_insensitive) soft-null DEP+coerce (#29756, ext/standard/string.c Z_PARAM_BOOL)
--FILE--
<?php
set_error_handler(static function (int $no, string $msg): bool {
if (E_DEPRECATED === $no) {
echo "DEP\n";

return true;
}

return false;
});
try {
$r = substr_compare('abc', 'ab', 0, 2, null);
echo (0 === $r ? 'OK' : 'BAD '.var_export($r, true)), "\n";
} catch (Throwable $e) {
echo get_class($e), ':', $e->getMessage(), "\n";
}
?>
--EXPECT--
DEP
OK
21 changes: 21 additions & 0 deletions test/compliance/cases/stdlib/substr_compare_null_ci_strict.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
stdlib substr_compare(null $case_insensitive) under strict_types TypeError (#29756, ext/standard/string.c Z_PARAM_BOOL)
--FILE--
<?php
declare(strict_types=1);

try {
substr_compare('abc', 'ab', 0, 2, null);
echo "uncaught\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
substr_compare('abc', 'ab', 0, 2, 1);
echo "uncaught-int\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
--EXPECT--
substr_compare(): Argument #5 ($case_insensitive) must be of type bool, null given
substr_compare(): Argument #5 ($case_insensitive) must be of type bool, int given
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
JIT: substr_compare(null $case_insensitive) under strict_types TypeError (#29756, ext/standard/string.c Z_PARAM_BOOL)
--FILE--
<?php
declare(strict_types=1);

try {
substr_compare('abc', 'ab', 0, 2, null);
echo "uncaught\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
substr_compare('abc', 'ab', 0, 2, 1);
echo "uncaught-int\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
--EXPECT--
substr_compare(): Argument #5 ($case_insensitive) must be of type bool, null given
substr_compare(): Argument #5 ($case_insensitive) must be of type bool, int given
14 changes: 14 additions & 0 deletions test/fixtures/aot/cases/substr_compare_null_ci_strict.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
AOT: substr_compare(null $case_insensitive) under strict_types TypeError (#29756, ext/standard/string.c Z_PARAM_BOOL)
--FILE--
<?php
declare(strict_types=1);

try {
echo substr_compare('abc', 'ab', 0, 2, null), "\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
substr_compare(): Argument #5 ($case_insensitive) must be of type bool, null given
9 changes: 9 additions & 0 deletions test/repro/issue_substr_compare_null_ci.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
// #29756 — substr_compare(..., null) $case_insensitive under strict_types → TypeError
declare(strict_types=1);

try {
var_dump(substr_compare('abc', 'ab', 0, 2, null));
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
9 changes: 9 additions & 0 deletions test/repro/issue_substr_compare_null_ci_aot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
// #29756 — AOT: substr_compare(..., null) $case_insensitive under strict_types → TypeError
declare(strict_types=1);

try {
echo substr_compare('abc', 'ab', 0, 2, null), "\n";
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
Loading