From 4b984fe0810a7f46fc01639f12feccdaacf6cc86 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 15 Jun 2015 17:07:36 +0200 Subject: added extra check for abstract keyword when adding abstract methods for interfaces --- include/interface.h | 8 +++++--- zend/classimpl.h | 10 +++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/interface.h b/include/interface.h index 5b15016..a93167f 100644 --- a/include/interface.h +++ b/include/interface.h @@ -51,13 +51,15 @@ public: */ Interface &method(const char *name, int flags, const Arguments &arguments = {}) { - // call base - ClassBase::method(name, flags, arguments); + // call base (an interface method is always public, so we add these flags, + // and although it is always abstract, PHP does not allow this flag, so we + // remove it in case the extension programmer had set it) + ClassBase::method(name, (Public | flags) & ~Abstract, arguments); // return self return *this; } - + /** * Extends exisiting PHP interface * diff --git a/zend/classimpl.h b/zend/classimpl.h index 5d0ab60..18802e3 100644 --- a/zend/classimpl.h +++ b/zend/classimpl.h @@ -414,7 +414,15 @@ public: * @param flags Optional flags (like public or protected) * @param args Description of the supported arguments */ - void method(const char *name, int flags=0, const Arguments &args = {}) { _methods.push_back(std::make_shared(name, (flags & (MethodModifiers | Static)) | Abstract , args)); } + void method(const char *name, int flags=0, const Arguments &args = {}) + { + // the "MethodModifiers" holds all the valid modifiers for a method: Final + Public + Protected + Private. + // The "Static" and "Abstract" properties are also valid modifiers in this context (in fact, you would + // expect that we could even force adding "Abstract" here, because we're adding an abstract method -- but + // in a PHP interface the "Abstract" modifier is not allowed - even though it is of course abstract. + // So we only _allow_ abstract here, and expect the caller to _set_ it. + _methods.push_back(std::make_shared(name, (flags & (MethodModifiers | Static | Abstract)), args)); + } /** * Add a property to the class -- cgit v1.2.3