Skip to content

Add Vec<(K,V)> to preserve insert order. #425

@Norbytus

Description

@Norbytus

While write tests for __call_static, some test running get error cause get wrong result,

use std::collections::HashMap;

use ext_php_rs::prelude::*;
use ext_php_rs::types::Zval;

pub fn startup(_ty: i32, _: i32) -> i32 {
    0
}

#[php_class]
#[derive(Default)]
struct Test {}

#[php_impl]
impl Test {
    #[php(constructor)]
    fn __constructor() -> Self {
        Self {}
    }
    pub fn __call_static(name: String, arguments: HashMap<String, &Zval>) -> Zval {
        let mut zval = Zval::new();
        if name == "callStaticSomeMagic" {
            let concat_args = format!(
                "Hello from static call {}",
                arguments
                    .iter()
                    .filter(|(_, v)| v.is_long())
                    .map(|(_, s)| s.long().unwrap().to_string())
                    .collect::<Vec<_>>()
                    .join(" ")
            );

            let _ = zval.set_string(&concat_args, false);
            zval
        } else {
            zval.set_null();
            zval
        }
    }
}

#[php_module]
fn module(module: ModuleBuilder) -> ModuleBuilder {
    module.class::<Test>()
}
<?php

$t = new Test;

var_dump($t::callStaticSomeMagic(1, 2, 3));
// Some time show correct result but some time input number in different order

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions