Skip to content

Syntax error on numeric literal suffixes in defaults #492

@Stranger6667

Description

@Stranger6667

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

  1. Update tests/src/integration/defaults/defaults.php with the PHP sample below
  2. Update tests/src/integration/defaults/mod.rs with the extension code below
  3. 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

  • ext-php-rs
  • macros
  • cli (cargo-php)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requestmacrosRelated to macros

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions