From 884316c2db6bb30cb9ff646c6a81f2e44ec6b259 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 24 Mar 2014 10:29:16 +0100 Subject: [PATCH] explained how to specify class constants --- documentation/properties.html | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/documentation/properties.html b/documentation/properties.html index f7f96c66..288a7e6d 100644 --- a/documentation/properties.html +++ b/documentation/properties.html @@ -148,6 +148,49 @@

Normal member variables

properties, but even that is probably not what you want, as storing data in native C++ variables is much faster.

+

Class constants

+

+ Class constants can be defined in a similar way as properties. The only + difference is that you have to pass in the flag 'Php::Const' instead of + one of the public, private or protected access modifiers. +

+

+


+#include <phpcpp.h>
+
+// @todo you class definition
+
+/**
+ *  Switch to C context so that the get_module() function can be
+ *  called by C programs (which the Zend engine is)
+ */
+extern "C" {
+    /**
+     *  Startup function for the extension
+     *  @return void*
+     */
+    PHPCPP_EXPORT void *get_module() {
+        // create static extension object
+        static Php::Extension myExtension("my_extension", "1.0");
+        
+        // description of the class so that PHP knows which methods are accessible
+        Php::Class<Example> example("Example");
+        
+        // the Example class has a class constant
+        example.property("MY_CONSTANT", "some value", Php::Const);
+        
+        // add the class to the extension
+        myExtension.add(std::move(example));
+        
+        // return the extension
+        return myExtension;
+    }
+}
+
+

+

+ The class constant can be accessed from PHP scripts using Example::MY_CONSTANT. +

Smart properties

With the magic methods __get() and __set() you