Potherca
12/3/2014 - 8:14 PM

Function to check whether or not a callable can be bound to a PHP object.

Function to check whether or not a callable can be bound to a PHP object.

<?php

namespace PhpHooligans;

/**
 * 
 * @param \Closure $callable
 *
 * @return bool
 */
function isBindable(\Closure $callable)
{
    $bindable = false;

    $reflectionFunction = new \ReflectionFunction($callable);
    if (
        $reflectionFunction->getClosureScopeClass() === null
        || $reflectionFunction->getClosureThis() !== null
    ) {
        $bindable = true;
    }

    return $bindable;
}

/*EOF*/