Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reflection of method type #2

Open
KarelWintersky opened this issue Aug 19, 2024 · 0 comments
Open

reflection of method type #2

KarelWintersky opened this issue Aug 19, 2024 · 0 comments

Comments

@KarelWintersky
Copy link
Contributor

Переделать код так, чтобы хэндлер \Path\To\Class::method вызывал не сразу статический класс, а сначала анализировал метод через рефлексию.

Зачем? Это полезно в рамках
https://youtrack.jetbrains.com/issue/WI-76233/Mozhno-li-sdelat-introspekciyu-koda-dlya-kastomnogo-frejmvorka-i-kak

Советуют, конечно, писать плагин https://plugins.jetbrains.com/docs/intellij/welcome.html , но это такое...

class foobar {
    public function a() {
        var_dump('S-');
    }

    static public function b() {
        var_dump('S+');
    }
}

$class = 'foobar';
$method = 'b';

$reflection = new ReflectionClass( $class );
$reflected_method = $reflection->getMethod( 'a' );

if ($reflected_method->isStatic()) {
    $handler =  [ $class, $method ];
} else {
    $handler = [ new $class, $method ];
}

call_user_func_array($handler, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant