summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-05 16:24:34 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-05 16:24:34 +0200
commit5973954b7428aa95ec8f0b2424b5725d2815049f (patch)
tree98f02a08bd8eaf8e7127e0aac97832f98f0ca217
parentffdccb83d460791202bdb258dbb9106da877da3b (diff)
added extra check to see if a derived class is initialized before a base class or interface
-rw-r--r--src/classimpl.cpp14
-rw-r--r--src/classimpl.h9
2 files changed, 21 insertions, 2 deletions
diff --git a/src/classimpl.cpp b/src/classimpl.cpp
index 98130dc..3999cf3 100644
--- a/src/classimpl.cpp
+++ b/src/classimpl.cpp
@@ -1397,7 +1397,14 @@ void ClassImpl::initialize(ClassBase *base, const std::string &prefix TSRMLS_DC)
}
// do we have a base class?
- if (_parent && _parent->_entry) entry.parent = _parent->_entry;
+ if (_parent)
+ {
+ // check if the base class was already defined
+ if (_parent->_entry) entry.parent = _parent->_entry;
+
+ // otherwise an error is reported
+ else std::cerr << "Derived class " << name() << " is initialized before base class " << _parent->name() << ": base class is ignored" << std::endl;
+ }
// register the class
_entry = zend_register_internal_class(&entry TSRMLS_CC);
@@ -1406,7 +1413,10 @@ void ClassImpl::initialize(ClassBase *base, const std::string &prefix TSRMLS_DC)
for (auto &interface : _interfaces)
{
// register this interface
- zend_class_implements(_entry TSRMLS_CC, 1, interface->_entry);
+ if (interface->_entry) zend_class_implements(_entry TSRMLS_CC, 1, interface->_entry);
+
+ // otherwise report an error
+ else std::cerr << "Derived class " << name() << " is initialized before base class " << interface->name() << ": interface is ignored" << std::endl;
}
// allocate doc comment to contain an empty string + a hidden pointer
diff --git a/src/classimpl.h b/src/classimpl.h
index f3673b1..cf28199 100644
--- a/src/classimpl.h
+++ b/src/classimpl.h
@@ -125,6 +125,15 @@ public:
virtual ~ClassImpl();
/**
+ * Retrieve the class name
+ * @return std::string
+ */
+ const std::string &name() const
+ {
+ return _name;
+ }
+
+ /**
* Retrieve the extension's class object
* @param entry
* @return ClassBase