summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Examples/CppClassesInPhp/cppclassinphp.cpp5
-rw-r--r--Examples/CppClassesInPhp/cppclassinphp.php7
-rw-r--r--include/class.h11
-rw-r--r--include/classbase.h2
-rw-r--r--src/classbase.cpp2
-rw-r--r--src/member.h2
-rw-r--r--src/method.h4
-rw-r--r--src/modifiers.cpp1
8 files changed, 24 insertions, 10 deletions
diff --git a/Examples/CppClassesInPhp/cppclassinphp.cpp b/Examples/CppClassesInPhp/cppclassinphp.cpp
index 8e9bf39..3164866 100644
--- a/Examples/CppClassesInPhp/cppclassinphp.cpp
+++ b/Examples/CppClassesInPhp/cppclassinphp.cpp
@@ -71,9 +71,8 @@ extern "C"
// add methods to it
customClass.add("myMethod", &MyCustomClass::myMethod, Php::Final, {});
- customClass.add("property", "bla");
- customClass.add("property", "bla", Php::Protected);
- customClass.add("property", "bla", Php::Const);
+ customClass.add("property1", "bla");
+ customClass.add("property2", "bla", Php::Protected);
// add the class to the extension
extension.add(customClass);
diff --git a/Examples/CppClassesInPhp/cppclassinphp.php b/Examples/CppClassesInPhp/cppclassinphp.php
index 1256018..cf1e42c 100644
--- a/Examples/CppClassesInPhp/cppclassinphp.php
+++ b/Examples/CppClassesInPhp/cppclassinphp.php
@@ -10,7 +10,10 @@
myFunction();
//create a MyCustomClass object, which is an object of a C++ class
-$MyCustomClass = new MyClass();
+$object = new MyClass();
// run a function of the class
-$MyCustomClass->myMethod(1);
+$object->myMethod(1);
+
+echo($object->property1."\n");
+echo($object->property2."\n");
diff --git a/include/class.h b/include/class.h
index bed9fa7..51cfb46 100644
--- a/include/class.h
+++ b/include/class.h
@@ -84,8 +84,15 @@ public:
* @param value Actual property value
* @param flags Optional flags
*/
- template <typename TYPE>
- void add(const char *name, const Type &value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, std::nullptr_t value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, uint64_t value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, uint32_t value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, uint16_t value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, char value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, const char *value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, const std::string &value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, bool value, int flags = Public) { ClassBase::add(name, value, flags); }
+ void add(const char *name, double value, int flags = Public) { ClassBase::add(name, value, flags); }
protected:
/**
diff --git a/include/classbase.h b/include/classbase.h
index 9fe1bda..9726e5a 100644
--- a/include/classbase.h
+++ b/include/classbase.h
@@ -61,7 +61,7 @@ public:
* @param that
*/
ClassBase(ClassBase &&that) :
- _flags(that._flags), _methods(std::move(that._methods)), _methods(std::move(that._methods)), _entry(that._entry)
+ _flags(that._flags), _methods(std::move(that._methods)), _members(std::move(that._members)), _entry(that._entry)
{
// other entry are invalid now (not that it is used..., class objects are
// only moved during extension setup, when the entry pointer has not yet
diff --git a/src/classbase.cpp b/src/classbase.cpp
index da705b6..38972f5 100644
--- a/src/classbase.cpp
+++ b/src/classbase.cpp
@@ -198,7 +198,7 @@ void ClassBase::initialize()
#endif
// set access types flags for class
- _entry->ce_flags = flags;
+ _entry->ce_flags = _flags;
// declare all member variables
for (auto &member : _members) member->initialize(_entry);
diff --git a/src/member.h b/src/member.h
index a1bce52..3ccdfad 100644
--- a/src/member.h
+++ b/src/member.h
@@ -30,7 +30,7 @@ public:
/**
* Destructor
*/
- virtual ~Member();
+ virtual ~Member() {}
/**
* Initialize the member
diff --git a/src/method.h b/src/method.h
index cc9f973..6a91068 100644
--- a/src/method.h
+++ b/src/method.h
@@ -46,6 +46,10 @@ public:
*/
void initialize(struct _zend_function_entry *entry, const std::string &classname)
{
+ // fix the flags, if neither public, private and protected is set, we use public,
+ // (this solves php warnings if only "final" or only "abstract" is set
+ if ((_flags & (Public|Private|Protected)) == 0) _flags |= Public;
+
// call base
Callable::initialize(entry, classname.c_str(), _flags);
}
diff --git a/src/modifiers.cpp b/src/modifiers.cpp
index 946b910..c987b8a 100644
--- a/src/modifiers.cpp
+++ b/src/modifiers.cpp
@@ -7,6 +7,7 @@
* @author Martijn Otto
* @copyright 2014 Copernica BV
*/
+#include "includes.h"
/**
* Set up namespace