Note, for ReflectionClass::getMethods() not all methods in a final class are final, just the ones that have explicit modifier.
If you want to use an and operator for the filter, here is a simple implementation
<?php
final class Apple {
public function publicMethod() { }
public final function publicFinalMethod() { }
protected final function protectedFinalMethod() { }
private static function privateStaticMethod() { }
}
class MyReflection extends ReflectionClass {
public function __construct($argument) {
parent::__construct($argument);
}
/**
* (non-PHPdoc)
* @see ReflectionClass::getMethods()
*/
public function getMethods($filter = null, $useAndOperator = true) {
if ($useAndOperator !== true) {
return parent::getMethods($filter);
}
$methods = parent::getMethods($filter);
$results = array();
foreach ($methods as $method) {
if (($method->getModifiers() & $filter) === $filter) {
$results[] = $method;
}
}
return $results;
}
}
$class = new MyReflection('Apple');
$methods = $class->getMethods(ReflectionMethod::IS_FINAL | ReflectionMethod::IS_PUBLIC);
var_dump($methods);
$methods = $class->getMethods(ReflectionMethod::IS_FINAL | ReflectionMethod::IS_PUBLIC, false);
var_dump($methods);
?>
Result:
array(1) {
[0]=>
object(ReflectionMethod)#4 (2) {
["name"]=>
string(17) "publicFinalMethod"
["class"]=>
string(5) "Apple"
}
}
array(3) {
[0]=>
&object(ReflectionMethod)#5 (2) {
["name"]=>
string(12) "publicMethod"
["class"]=>
string(5) "Apple"
}
[1]=>
&object(ReflectionMethod)#3 (2) {
["name"]=>
string(17) "publicFinalMethod"
["class"]=>
string(5) "Apple"
}
[2]=>
&object(ReflectionMethod)#6 (2) {
["name"]=>
string(20) "protectedFinalMethod"
["class"]=>
string(5) "Apple"
}
}