2
<?php
class StorageMapper
{
    public function __invoke(string $entity, array $storageServices): StorageServiceInterface
    {
        $globalEntities = [
            'Customer::class',
            'CustomerSetting::class',
            'UserSetting::class',
        ];

        return \in_array($entity, $globalEntities, true) ?
            $storageServices['db1'] :
            $storageServices['db2'];
    }

    public function __call($name, $args) {
        // Hello
    }
    
    public static function __callStatic($name, $arguments)
    {
        // Note: value of $name is case sensitive.
        echo "Calling static method '$name' "
             . implode(', ', $arguments). "\n";
    }
}

echo(is_callable(StorageMapper::class) ? 'true' : 'false');

It should see this class as callable, since it has __invoke, and even has __callStatic methods. Why doesn't it? How should this be fixed?

Lehren
  • 99
  • 2
  • 11
  • A class [name] isn't callable. It's instantiable, if anything. – deceze Mar 31 '22 at 11:31
  • @deceze then what about "A class name is callable if it implements `__callStatic().`" from the [manual](https://www.php.net/manual/en/function.is-callable.php#refsect1-function.is-callable-notes)? – u_mulder Mar 31 '22 at 12:17
  • @u_mulder Mmm, looks like a documentation bug. `__callStatic` enables `$className::foo()`, not `$className()`. So it doesn't make the classname itself directly "callable". – deceze Mar 31 '22 at 12:19

0 Answers0