Eloquent\Phony\Reflection\FeatureDetector::standardFeatures PHP Method

standardFeatures() public method

Get the standard feature detection callbacks.
public standardFeatures ( ) : callable>\array
return callable>\array
    public function standardFeatures()
    {
        return array('class.anonymous' => function ($detector) {
            return $detector->checkInternalMethod('ReflectionClass', 'isAnonymous');
        }, 'closure' => function ($detector) {
            return $detector->checkInternalClass('Closure');
        }, 'closure.bind' => function ($detector) {
            return $detector->checkInternalMethod('Closure', 'bind');
        }, 'constant.array' => function ($detector) {
            // syntax causes fatal on PHP < 5.6
            if ($detector->isSupported('runtime.php')) {
                if (version_compare(PHP_VERSION, '5.6.x', '<')) {
                    return false;
                    // @codeCoverageIgnore
                }
            }
            // syntax causes fatal on HHVM
            if ($detector->isSupported('runtime.hhvm')) {
                return false;
                // @codeCoverageIgnore
            }
            return $detector->checkStatement(sprintf('const %s=array()', $detector->uniqueSymbolName()), false);
        }, 'constant.class.array' => function ($detector) {
            // syntax causes fatal on PHP < 5.6
            if ($detector->isSupported('runtime.php')) {
                if (version_compare(PHP_VERSION, '5.6.x', '<')) {
                    return false;
                    // @codeCoverageIgnore
                }
            }
            // syntax causes fatal on HHVM
            if ($detector->isSupported('runtime.hhvm')) {
                return false;
                // @codeCoverageIgnore
            }
            return $detector->checkStatement(sprintf('class %s{const A=array();}', $detector->uniqueSymbolName()), false);
        }, 'constant.class.expression' => function ($detector) {
            return $detector->checkStatement(sprintf('class %s{const A=0+0;}', $detector->uniqueSymbolName()), false);
        }, 'constant.expression' => function ($detector) {
            return $detector->checkStatement(sprintf('const %s=0+0', $detector->uniqueSymbolName()), false);
        }, 'error.exception.engine' => function ($detector) {
            return $detector->checkInternalClass('Error');
        }, 'generator' => function ($detector) {
            return $detector->checkInternalClass('Generator');
        }, 'generator.implicit-next' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('$f=function(){yield 0;yield 1;};$g=$f();$g->next();' . 'return 1===$g->current();', false);
        }, 'generator.exception' => function ($detector) {
            return $detector->checkInternalMethod('Generator', 'throw');
        }, 'generator.yield' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('yield 0', true);
        }, 'generator.yield.assign' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('$x=yield 0', true);
        }, 'generator.yield.assign.key' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('$x=yield 0=>0', true);
        }, 'generator.yield.assign.nothing' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('$x=yield', true);
        }, 'generator.yield.expression' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('(yield 0)', true);
        }, 'generator.yield.expression.assign' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('$x=(yield 0)', true);
        }, 'generator.yield.expression.assign.key' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('$x=(yield 0=>0)', true);
        }, 'generator.yield.expression.assign.nothing' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('$x=(yield)', true);
        }, 'generator.yield.expression.key' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('(yield 0=>0)', true);
        }, 'generator.yield.expression.nothing' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('(yield)', true);
        }, 'generator.yield.key' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('yield 0=>0', true);
        }, 'generator.yield.nothing' => function ($detector) {
            return $detector->isSupported('generator') && $detector->checkStatement('yield', true);
        }, 'generator.return' => function ($detector) {
            return $detector->checkInternalMethod('Generator', 'getReturn');
        }, 'object.constructor.php4' => function ($detector) {
            if ($detector->isSupported('runtime.hhvm')) {
                return true;
                // @codeCoverageIgnore
            }
            return version_compare(PHP_VERSION, '7.x', '<');
        }, 'object.constructor.bypass' => function ($detector) {
            return $detector->checkInternalMethod('ReflectionClass', 'newInstanceWithoutConstructor');
        }, 'object.constructor.bypass.extended-internal' => function ($detector) {
            if (!$detector->isSupported('object.constructor.bypass')) {
                return false;
                // @codeCoverageIgnore
            }
            $symbol = $detector->uniqueSymbolName();
            $exportedSymbol = var_export($symbol, true);
            return $detector->checkStatement(sprintf('class %s extends ArrayObject{}' . '$r=new ReflectionClass(%s);$o=0;try{' . '$o=$r->newInstanceWithoutConstructor();' . '}catch(Throwable $e){}catch(Exception $e){}' . 'return $o instanceof %s;', $symbol, $exportedSymbol, $symbol), false);
        }, 'parameter.default.constant' => function ($detector) {
            return $detector->checkInternalMethod('ReflectionParameter', 'isDefaultValueConstant');
        }, 'parameter.type.self.override' => function ($detector) {
            if ($detector->isSupported('runtime.hhvm')) {
                return true;
                // @codeCoverageIgnore
            }
            return !version_compare(PHP_VERSION, '5.4.1.x', '<');
        }, 'parameter.variadic' => function ($detector) {
            return $detector->checkStatement('function (...$a) {};', true);
        }, 'parameter.variadic.reference' => function ($detector) {
            // syntax causes fatal on HHVM
            if ($detector->isSupported('runtime.hhvm')) {
                return false;
                // @codeCoverageIgnore
            }
            return $detector->checkStatement('function (&...$a) {};', true);
        }, 'parameter.variadic.type' => function ($detector) {
            // syntax causes fatal on HHVM
            if ($detector->isSupported('runtime.hhvm')) {
                return false;
                // @codeCoverageIgnore
            }
            return $detector->checkStatement('function (stdClass ...$a) {};', true);
        }, 'parameter.hint.scalar' => function ($detector) {
            return $detector->checkInternalMethod('ReflectionParameter', 'getType');
        }, 'parser.relaxed-keywords' => function ($detector) {
            // syntax causes fatal on PHP < 7.0 and HHVM
            return $detector->isSupported('runtime.php') && !version_compare(PHP_VERSION, '7.x', '<');
        }, 'return.type' => function ($detector) {
            return $detector->checkInternalMethod('ReflectionFunctionAbstract', 'hasReturnType');
        }, 'reflection.function.export.default.array' => function () {
            $function = new ReflectionFunction(function ($a0 = array('a')) {
            });
            return false !== strpos(strval($function), "'a'");
        }, 'reflection.function.export.reference' => function () {
            $function = new ReflectionFunction(function (&$a0) {
            });
            return false !== strpos(strval($function), '&');
        }, 'runtime.hhvm' => function ($detector) {
            return 'hhvm' === $detector->runtime();
        }, 'runtime.php' => function ($detector) {
            return 'php' === $detector->runtime();
        }, 'stdout.ansi' => function () {
            // @codeCoverageIgnoreStart
            if (DIRECTORY_SEPARATOR === '\\') {
                return 0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM') || false !== getenv('BABUN_HOME');
            }
            // @codeCoverageIgnoreEnd
            return function_exists('posix_isatty') && @posix_isatty(STDOUT);
        }, 'trait' => function ($detector) {
            return $detector->checkInternalMethod('ReflectionClass', 'isTrait');
        }, 'type.callable' => function ($detector) {
            return $detector->checkInternalMethod('ReflectionParameter', 'isCallable');
        }, 'type.iterable' => function () {
            try {
                $function = new ReflectionFunction(function (iterable $a) {
                });
                $parameters = $function->getParameters();
                $result = null === $parameters[0]->getClass();
            } catch (ReflectionException $e) {
                $result = false;
            }
            return $result;
        }, 'type.nullable' => function ($detector) {
            // syntax causes fatal on HHVM
            if ($detector->isSupported('runtime.hhvm')) {
                return false;
                // @codeCoverageIgnore
            }
            return $detector->checkStatement('function(?int $a){}', false);
        }, 'type.void' => function ($detector) {
            // @codeCoverageIgnoreStart
            if (!$detector->isSupported('return.type')) {
                return false;
            }
            // @codeCoverageIgnoreEnd
            return $detector->checkStatement('$r=new ReflectionFunction(function():void{});' . 'return $r->getReturnType()->isBuiltin();', false);
        });
    }