Skip to content

bermudaphp/reflection-type-matcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Install

composer require bermudaphp/reflection-type-matcher

Usage

    $reflector = new ReflectionFunction(static fn(int $a, int $b) => $a + $b);
    $param = $reflector->getParameters()[0];
    
    $matcher = new TypeMatcher();
    
    $matcher->match($param->getType(), '22'); // false
    $matcher->match($param->getType(), 22); // true
    
    $reflector = new ReflectionFunction(static fn(A&B $arg) => $arg);
    $param = $reflector->getParameters()[0];
    
    $matcher->match($param->getType(), new class implements A, B {}) // true
    $matcher->match($param->getType(), new StdClass) // false