HasFilteredProperties::check()

Not yet in a tagged release

Description

HasFilteredProperties::check() - does a class or object have properties that pass the filter?

// remember to import first
use GanbaroDigital\MissingBits\ClassesAndObjects\HasFilteredProperties;

// our method signature
bool HasFilteredProperties::check(ReferenceClass $target, int $propTypes, callable $resultFilter);

Parameters

HasFilteredProperties::check() takes three parameters:

The Result Filter

The $resultFilter parameter is a callable. It must have this function signature:

boolean function(ReflectionProperty $refProp);

where:

HasFilteredProperties::check() will call $resultFilter() with each discovered property. If your $resultFilter callable returns true, HasFilteredProperties::check() will stop discovering properties and return true to the caller.

For example:

// in this example, $target is the object that we want to filter
$resultFilter = function(ReflectionProperty $refProp) use($target) {
    // only store object properties
    if (!$refProp->isStatic()) {
        return false;
    }

    return true;
};

Return Value

HasFilteredProperties::check() returns a boolean:

Throws

HasFilteredProperties::check() does not throw any exceptions.