Doc #73195 [Ana]: ReflectionClass::getMethod() filter arguments doesn't accept combinations

From: Date: Wed, 28 Sep 2016 16:29:09 +0000
Subject: Doc #73195 [Ana]: ReflectionClass::getMethod() filter arguments doesn't accept combinations
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-13959@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73195&edit=1 ID: 73195 Updated by: johannes@php.net Reported by: grgtvs at gmail dot com Summary: ReflectionClass::getMethod() filter arguments doesn't accept combinations Status: Analyzed Type: Documentation Problem Package: Reflection related Operating System: GNU/Linux PHP Version: Irrelevant -Assigned To: johannes +Assigned To: cmb Block user comment: N Private report: N New Comment: I believe this was designed to do only "positive" filtering. If we get negation to work I believe we should do this and add an example to the docs. Do you have karma, cmb? Previous Comments: ------------------------------------------------------------------------ [2016-09-28 15:49:17] cmb@php.net The following patch has been added/updated: Patch Name: 73195 Revision: 1475077757 URL: https://bugs.php.net/patch-display.php?bug=73195&patch=73195&revision=1475077757 ------------------------------------------------------------------------ [2016-09-28 15:48:59] cmb@php.net The issue is not the logical disjunction (|), but rather the negation (~) in combination with the fact, that getMethods() simply checks, whether the logical conjunction (&) of the given filter value and the stored value is non-zero. Even if there were no hidden flags (but there are), ~ReflectionMethod::IS_PUBLIC would catch final methods, for instance. I'm not sure whether that is a bug, or just a documentation issue. Anyhow, the fix appears to be trivial (see the attached 73195.patch). Johannes, as you're listed as mainter of ext/reflection, what do you think? ------------------------------------------------------------------------ [2016-09-28 10:05:11] grgtvs at gmail dot com This seems just to be an undocumented issue not a bug ------------------------------------------------------------------------ [2016-09-28 09:35:01] grgtvs at gmail dot com Description: ------------ It seems that when using filters argument with combinations of the constants ReflectionMethod::IS_STATIC, ReflectionMethod::IS_PUBLIC, ReflectionMethod::IS_PROTECTED, ReflectionMethod::IS_PRIVATE, ReflectionMethod::IS_ABSTRACT, ReflectionMethod::IS_FINAL - e.g $reflectionClassObj->getMethod(~ReflectionMethod::IS_PUBLIC) or $reflectionClassObj->getMethod(ReflectionMethod::IS_PUBLIC & ~ReflectionMethod::IS_STATIC) etc. the method tends to return every method as it would do without defining any filters. I've tried this on PHP 5.5.9 as well as at 7.0.8 and the result is the same. Test script: --------------- class MyClass { final public function iamFinalPublic() { } public function iamPublic() { } } function testReflection() { $refl = new ReflectionClass(MyClass::class); $methods = $refl->getMethods(~ReflectionMethod::IS_PUBLIC); return count($methods); } echo testReflection(); Expected result: ---------------- 0 Actual result: -------------- 2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73195&edit=1

« previous php.doc.bugs (#13959) next »