Description
When a Rust function has multiple arguments and one of them is of the usize type, and the provided default value for this argument uses the _usize suffix, it leads to a syntax error on the PHP side when that other arguments is passed but the usize one is omitted.
Steps to Reproduce
- Update
tests/src/integration/defaults/defaults.php with the PHP sample below
- Update
tests/src/integration/defaults/mod.rs with the extension code below
- Run
cargo test --release --all integration::defaults::tests::defaults_works
Example
Extension Code:
#[php_function]
#[php(defaults(a = 42_usize, b = None))]
pub fn test_defaults_with_numeric_literal_type_suffix(
a: usize,
b: Option<String>,
) -> PhpResult<usize> {
Ok(b.map(|b| b.len()).unwrap_or(a))
}
pub fn build_module(builder: ModuleBuilder) -> ModuleBuilder {
builder
.function(wrap_function!(test_defaults_with_numeric_literal_type_suffix))
}
PHP Code:
<?php
assert(test_defaults_with_numeric_literal_type_suffix() === 42);
assert(test_defaults_with_numeric_literal_type_suffix(5) === 5);
assert(test_defaults_with_numeric_literal_type_suffix(b: "b") === 1);
assert(test_defaults_with_numeric_literal_type_suffix(5, b: "b") === 1);
Actual Behavior
thread 'integration::defaults::tests::defaults_works' panicked at tests/src/integration/mod.rs:113:13:
status: exit status: 255
stdout:
stderr: PHP Parse error: syntax error, unexpected identifier "_usize" in on line 1
Expected Behavior
The PHP snippet above should not fail
Log Output
Affected Components
PHP Version
PHP 8.4.10 (cli) (built: Jul 4 2025 12:41:44) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.10, Copyright (c) Zend Technologies
ext-php-rs Version
0.14.1
Operating System
No response
Description
When a Rust function has multiple arguments and one of them is of the
usizetype, and the provided default value for this argument uses the_usizesuffix, it leads to a syntax error on the PHP side when that other arguments is passed but theusizeone is omitted.Steps to Reproduce
tests/src/integration/defaults/defaults.phpwith the PHP sample belowtests/src/integration/defaults/mod.rswith the extension code belowcargo test --release --all integration::defaults::tests::defaults_worksExample
Extension Code:
PHP Code:
Actual Behavior
Expected Behavior
The PHP snippet above should not fail
Log Output
Affected Components
PHP Version
ext-php-rsVersion0.14.1
Operating System
No response