summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-06-15 17:07:36 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-06-15 17:07:36 +0200
commit4b984fe0810a7f46fc01639f12feccdaacf6cc86 (patch)
treecfe0fcf389f853de53c3d13c1b37be464b55f6d4
parent76f8a944540a84b6a5c98135bd9f9e6e996fe37d (diff)
added extra check for abstract keyword when adding abstract methods for interfaces
-rw-r--r--include/interface.h8
-rw-r--r--zend/classimpl.h10
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<Method>(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<Method>(name, (flags & (MethodModifiers | Static | Abstract)), args));
+ }
/**
* Add a property to the class