diff --git a/ext/standard/str_contains.php b/ext/standard/str_contains.php index b81b6a7c499..f223cead98e 100644 --- a/ext/standard/str_contains.php +++ b/ext/standard/str_contains.php @@ -33,18 +33,8 @@ public function execute(Frame $frame): void $this->requireExactArgCount($frame, 'str_contains', 2); InternalStrictArg::rejectNullString($frame->calledArgs[0], 'str_contains', 'haystack', 0, $frame); InternalStrictArg::rejectNullString($frame->calledArgs[1], 'str_contains', 'needle', 1, $frame); - $haystackStr = VmString::coerceStringBuiltinArgNoObject( - $frame->calledArgs[0], - 'str_contains', - 0, - 'haystack' - ); - $needleStr = VmString::coerceStringBuiltinArgNoObject( - $frame->calledArgs[1], - 'str_contains', - 1, - 'needle' - ); + $haystackStr = self::vmStringArg($frame, 0, 'haystack'); + $needleStr = self::vmStringArg($frame, 1, 'needle'); BuiltinExecute::writeReturn( $frame, static function (Variable $ret) use ($haystackStr, $needleStr): void { @@ -68,9 +58,23 @@ public function call(Context $context, JITVariable ...$args): Value } JitInternalStrictArg::rejectNullString($context, $args[0], 'str_contains', 'haystack', 1); JitInternalStrictArg::rejectNullString($context, $args[1], 'str_contains', 'needle', 2); - $hay = JitStringBuiltinArg::lower($context, $args[0], 'str_contains', 0, 'haystack'); - $needle = JitStringBuiltinArg::lower($context, $args[1], 'str_contains', 1, 'needle'); + $hay = JitStringBuiltinArg::lowerCoercible($context, $args[0], 'str_contains', 0, 'haystack'); + $needle = JitStringBuiltinArg::lowerCoercible($context, $args[1], 'str_contains', 1, 'needle'); return StringStrContains::invokeContains($context, $hay, $needle); } + + private static function vmStringArg(Frame $frame, int $argIndex, string $paramName): string + { + if (InternalStrictArg::isCallerStrict($frame)) { + return InternalStrictArg::requireString($frame, $argIndex, 'str_contains', $paramName)->toString(); + } + + return VmString::coerceStringBuiltinArg( + $frame->calledArgs[$argIndex], + 'str_contains', + $argIndex, + $paramName + ); + } } diff --git a/ext/standard/str_ends_with.php b/ext/standard/str_ends_with.php index 0bf6f890f64..4a9ecb16424 100644 --- a/ext/standard/str_ends_with.php +++ b/ext/standard/str_ends_with.php @@ -33,18 +33,8 @@ public function execute(Frame $frame): void $this->requireExactArgCount($frame, 'str_ends_with', 2); InternalStrictArg::rejectNullString($frame->calledArgs[0], 'str_ends_with', 'haystack', 0, $frame); InternalStrictArg::rejectNullString($frame->calledArgs[1], 'str_ends_with', 'needle', 1, $frame); - $haystackStr = VmString::coerceStringBuiltinArgNoObject( - $frame->calledArgs[0], - 'str_ends_with', - 0, - 'haystack' - ); - $needleStr = VmString::coerceStringBuiltinArgNoObject( - $frame->calledArgs[1], - 'str_ends_with', - 1, - 'needle' - ); + $haystackStr = self::vmStringArg($frame, 0, 'haystack'); + $needleStr = self::vmStringArg($frame, 1, 'needle'); BuiltinExecute::writeReturn( $frame, static fn (Variable $ret) => $ret->bool(VmString::endsWith($haystackStr, $needleStr)) @@ -58,9 +48,23 @@ public function call(Context $context, JITVariable ...$args): Value } JitInternalStrictArg::rejectNullString($context, $args[0], 'str_ends_with', 'haystack', 1); JitInternalStrictArg::rejectNullString($context, $args[1], 'str_ends_with', 'needle', 2); - $hay = JitStringBuiltinArg::lower($context, $args[0], 'str_ends_with', 0, 'haystack'); - $needle = JitStringBuiltinArg::lower($context, $args[1], 'str_ends_with', 1, 'needle'); + $hay = JitStringBuiltinArg::lowerCoercible($context, $args[0], 'str_ends_with', 0, 'haystack'); + $needle = JitStringBuiltinArg::lowerCoercible($context, $args[1], 'str_ends_with', 1, 'needle'); return StringStrContains::invokeEndsWith($context, $hay, $needle); } + + private static function vmStringArg(Frame $frame, int $argIndex, string $paramName): string + { + if (InternalStrictArg::isCallerStrict($frame)) { + return InternalStrictArg::requireString($frame, $argIndex, 'str_ends_with', $paramName)->toString(); + } + + return VmString::coerceStringBuiltinArg( + $frame->calledArgs[$argIndex], + 'str_ends_with', + $argIndex, + $paramName + ); + } } diff --git a/ext/standard/str_starts_with.php b/ext/standard/str_starts_with.php index 613b38e361f..01425d526c8 100644 --- a/ext/standard/str_starts_with.php +++ b/ext/standard/str_starts_with.php @@ -33,18 +33,8 @@ public function execute(Frame $frame): void $this->requireExactArgCount($frame, 'str_starts_with', 2); InternalStrictArg::rejectNullString($frame->calledArgs[0], 'str_starts_with', 'haystack', 0, $frame); InternalStrictArg::rejectNullString($frame->calledArgs[1], 'str_starts_with', 'needle', 1, $frame); - $haystackStr = VmString::coerceStringBuiltinArgNoObject( - $frame->calledArgs[0], - 'str_starts_with', - 0, - 'haystack' - ); - $needleStr = VmString::coerceStringBuiltinArgNoObject( - $frame->calledArgs[1], - 'str_starts_with', - 1, - 'needle' - ); + $haystackStr = self::vmStringArg($frame, 0, 'haystack'); + $needleStr = self::vmStringArg($frame, 1, 'needle'); BuiltinExecute::writeReturn( $frame, static fn (Variable $ret) => $ret->bool(VmString::startsWith($haystackStr, $needleStr)) @@ -58,9 +48,23 @@ public function call(Context $context, JITVariable ...$args): Value } JitInternalStrictArg::rejectNullString($context, $args[0], 'str_starts_with', 'haystack', 1); JitInternalStrictArg::rejectNullString($context, $args[1], 'str_starts_with', 'needle', 2); - $hay = JitStringBuiltinArg::lower($context, $args[0], 'str_starts_with', 0, 'haystack'); - $needle = JitStringBuiltinArg::lower($context, $args[1], 'str_starts_with', 1, 'needle'); + $hay = JitStringBuiltinArg::lowerCoercible($context, $args[0], 'str_starts_with', 0, 'haystack'); + $needle = JitStringBuiltinArg::lowerCoercible($context, $args[1], 'str_starts_with', 1, 'needle'); return StringStrContains::invokeStartsWith($context, $hay, $needle); } + + private static function vmStringArg(Frame $frame, int $argIndex, string $paramName): string + { + if (InternalStrictArg::isCallerStrict($frame)) { + return InternalStrictArg::requireString($frame, $argIndex, 'str_starts_with', $paramName)->toString(); + } + + return VmString::coerceStringBuiltinArg( + $frame->calledArgs[$argIndex], + 'str_starts_with', + $argIndex, + $paramName + ); + } }