Skip to content

Commit

Permalink
explained how to specify class constants
Browse files Browse the repository at this point in the history
  • Loading branch information
EmielBruijntjes committed Mar 24, 2014
1 parent d41e5b4 commit 884316c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions documentation/properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,49 @@ <h2 id="normal-members">Normal member variables</h2>
properties, but even that is probably not what you want, as storing
data in native C++ variables is much faster.
</p>
<h2 id="constants">Class constants</h2>
<p>
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.
</p>
<p>
<pre class="language-cpp"><code>
#include &lt;phpcpp.h&gt;

// @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&lt;Example&gt; 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;
}
}
</code></pre>
</p>
<p>
The class constant can be accessed from PHP scripts using Example::MY_CONSTANT.
</p>
<h2>Smart properties</h2>
<p>
With the <a href="magic-methods">magic methods __get() and __set()</a> you
Expand Down

0 comments on commit 884316c

Please sign in to comment.