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
4 changes: 2 additions & 2 deletions ext/standard/get_browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function execute(Frame $frame): void
if ($argc >= 1) {
$uaArg = $frame->calledArgs[0]->resolveIndirect();
if (Variable::TYPE_NULL !== $uaArg->type) {
$ua = VmString::coerceStringBuiltinArg($frame->calledArgs[0], 'get_browser', 0, 'browser_name');
$ua = VmString::coerceStringBuiltinArg($frame->calledArgs[0], 'get_browser', 0, 'user_agent');
}
}
if ($argc >= 2) {
Expand Down Expand Up @@ -102,7 +102,7 @@ public function call(Context $context, JITVariable ...$args): Value
throw new \LogicException('get_browser() expects at most 2 arguments in this compiler build');
}
if ($argc >= 1 && JITVariable::TYPE_NULL !== $args[0]->type) {
JitStringBuiltinArg::lower($context, $args[0], 'get_browser', 0, 'browser_name');
JitStringBuiltinArg::lower($context, $args[0], 'get_browser', 0, 'user_agent');
}
if ($argc >= 2) {
// Compile-time null under strict: catchable TypeError then stop IR (#31289 / peer hash #31288).
Expand Down
3 changes: 2 additions & 1 deletion lib/BuiltinParamNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,9 @@ public static function forFunction(string $name): ?array
case 'stream_set_blocking':
case 'socket_set_blocking': // PHP_FALIAS
return ['stream', 'enable'];
// php-src ext/standard/basic_functions.stub.php — $user_agent not $browser_name (#23382)
case 'get_browser':
return ['browser_name', 'return_array'];
return ['user_agent=', 'return_array='];
case 'get_defined_constants':
// php-src Zend/zend_builtin_functions.stub.php — arity 1 on every version (#28522).
return ['categorize'];
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@
<file>./test/compliance/CallbackFilterIteratorReflectionNamed28721JITTest.php</file>
<file>./test/compliance/IteratorApplyReflectionNamed23445VMTest.php</file>
<file>./test/compliance/IteratorApplyReflectionNamed23445JITTest.php</file>
<file>./test/compliance/GetBrowserReflectionNamed23382VMTest.php</file>
<file>./test/compliance/GetBrowserReflectionNamed23382JITTest.php</file>
<file>./test/compliance/StreamContextGetOptionsExcessArgc30785VMTest.php</file>
<file>./test/compliance/StreamContextGetOptionsExcessArgc30785JITTest.php</file>
<file>./test/compliance/HighlightMetaExcessArgc30723VMTest.php</file>
Expand Down
20 changes: 20 additions & 0 deletions test/compliance/GetBrowserReflectionNamed23382JITTest.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 JIT PHPT for get_browser Reflection/named args (#23382). */
final class GetBrowserReflectionNamed23382JITTest extends BaseTest
{
protected string $BIN = __DIR__.'/../../bin/jit.php';

public static function providePHPTests(): \Generator
{
$path = __DIR__.'/cases/stdlib/get_browser_reflection_named.phpt';
[$name, $code, $sections] = self::parsePHPT($path, 'get_browser_reflection_named');
yield $name => [$name, $code, $sections];
}
}
20 changes: 20 additions & 0 deletions test/compliance/GetBrowserReflectionNamed23382VMTest.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 get_browser Reflection/named args (#23382). */
final class GetBrowserReflectionNamed23382VMTest extends BaseTest
{
protected string $BIN = __DIR__.'/../../bin/vm.php';

public static function providePHPTests(): \Generator
{
$path = __DIR__.'/cases/stdlib/get_browser_reflection_named.phpt';
[$name, $code, $sections] = self::parsePHPT($path, 'get_browser_reflection_named');
yield $name => [$name, $code, $sections];
}
}
22 changes: 22 additions & 0 deletions test/compliance/cases/stdlib/get_browser_reflection_named.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
get_browser Reflection user_agent/return_array + named args (#23382, php-src-strict)
--FILE--
<?php
$rf = new ReflectionFunction('get_browser');
$names = [];
foreach ($rf->getParameters() as $p) {
$names[] = $p->getName();
}
echo implode(',', $names), "\n";
var_export(@get_browser(user_agent: null, return_array: true));
echo "\n";
try {
get_browser(browser_name: null);
echo "unexpected browser_name ok\n";
} catch (Throwable $e) {
echo get_class($e), "\n";
}
--EXPECT--
user_agent,return_array
false
Error
22 changes: 22 additions & 0 deletions test/repro/issue_23382_get_browser_reflection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

// Issue #23382 — get_browser Reflection/named args are user_agent/return_array (not browser_name).
$rf = new ReflectionFunction('get_browser');
$names = [];
foreach ($rf->getParameters() as $p) {
$names[] = $p->getName();
}
echo implode(',', $names), "\n";
try {
// Named bind must succeed; browscap may be unset (false / warning is fine).
var_export(@get_browser(user_agent: null, return_array: true));
echo "\n";
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
try {
get_browser(browser_name: null);
echo "unexpected browser_name ok\n";
} catch (Throwable $e) {
echo get_class($e), "\n";
}
Loading