@@ -148,6 +148,49 @@ <h2 id="normal-members">Normal member variables</h2>
148148 properties, but even that is probably not what you want, as storing
149149 data in native C++ variables is much faster.
150150</ p >
151+ < h2 id ="constants "> Class constants</ h2 >
152+ < p >
153+ Class constants can be defined in a similar way as properties. The only
154+ difference is that you have to pass in the flag 'Php::Const' instead of
155+ one of the public, private or protected access modifiers.
156+ </ p >
157+ < p >
158+ < pre class ="language-cpp "> < code >
159+ #include <phpcpp.h>
160+
161+ // @todo you class definition
162+
163+ /**
164+ * Switch to C context so that the get_module() function can be
165+ * called by C programs (which the Zend engine is)
166+ */
167+ extern "C" {
168+ /**
169+ * Startup function for the extension
170+ * @return void*
171+ */
172+ PHPCPP_EXPORT void *get_module() {
173+ // create static extension object
174+ static Php::Extension myExtension("my_extension", "1.0");
175+
176+ // description of the class so that PHP knows which methods are accessible
177+ Php::Class<Example> example("Example");
178+
179+ // the Example class has a class constant
180+ example.property("MY_CONSTANT", "some value", Php::Const);
181+
182+ // add the class to the extension
183+ myExtension.add(std::move(example));
184+
185+ // return the extension
186+ return myExtension;
187+ }
188+ }
189+ </ code > </ pre >
190+ </ p>
191+ < p >
192+ The class constant can be accessed from PHP scripts using Example::MY_CONSTANT.
193+ </ p >
151194< h2 > Smart properties</ h2 >
152195< p >
153196 With the < a href ="magic-methods "> magic methods __get() and __set()</ a > you
0 commit comments