PHP code example of bermudaphp / reflection-type-matcher
1. Go to this page and download the library: Download bermudaphp/reflection-type-matcher library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bermudaphp / reflection-type-matcher example snippets
$reflector = new ReflectionFunction(static fn(int $a, int $b) => $a + $b);
$param = $reflector->getParameters()[0];
TypeMatcher::match($param->getType(), '22'); // true
TypeMatcher::match($param->getType(), 22); // true
TypeMatcher::match($param->getType(), '22', true); // false
$reflector = new ReflectionFunction(static fn(A&B $arg) => $arg);
$param = $reflector->getParameters()[0];
TypeMatcher::match($param->getType(), new class implements A, B {}) // true
TypeMatcher::match($param->getType(), new StdClass) // false