alexdodonov / mezon-router

Small and fast router
https://twitter.com/mezonphp
267 stars 18 forks source link

Static method callable checker error: "must be callable entity" #30

Closed BurakBoz closed 2 years ago

BurakBoz commented 2 years ago

Hi, I've upgraded my composer packages via composer update command Currently I'm running on mezon/router@1.3.5 I've got this error on my own framework after version upgrade and none of my routes are not working now. global.ERROR: Router Caught An Exception: 0;'uFramework\Controller\settings::routeIndex' must be callable entity [] []

Something wrong about this checker method. It cannot check static class methods are really exists and callable.

    /**
     * Checking that handler can be called
     *
     * @param object|array|callable|string $processor
     *            callback object
     * @param ?string $functionName
     *            callback method
     * @return bool
     * @psalm-suppress InvalidArrayAccess
     */
    private function canBeCalled($processor, ?string $functionName): bool
    {
        return is_callable($processor) && ($functionName !== null && is_object($processor[0]) && (method_exists($processor[0], $functionName) || isset($processor[0]->$functionName)));
    }

Here is the parameters when calling canBeCalled method. That class is exists, included and method is static.

Param: $processor
^ array:2 [▼
  0 => "uFramework\Controller\sites"
  1 => "routeIndex"
]

Param: $functionName
^ "routeIndex"

Temporarily I've changed code like this and it works now. I don't know why did you add more complex checks on that line but it brokes static method checks

private function canBeCalled($processor, ?string $functionName): bool
    {
        return is_callable($processor);
    }
alexdodonov commented 2 years ago

@BurakBoz Hi! Fixed. Download please version 1.3.5 once again.

Is it OK now?

BurakBoz commented 2 years ago

Hi, yes, problem solved thank you very much