summaryrefslogtreecommitdiff
path: root/documentation/classes-and-objects.html
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-06 11:42:12 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-06 11:42:12 +0100
commit2c8b750521ca88570c80531c6eeced8ee0ce117b (patch)
tree593c29fb27dc88fe0c8537b50635d0b7958d6b48 /documentation/classes-and-objects.html
parentf441e977685af67ff9f06013674bf8352dcb763a (diff)
changes to documentation, added support for const methods so that they can also be exported
Diffstat (limited to 'documentation/classes-and-objects.html')
-rw-r--r--documentation/classes-and-objects.html73
1 files changed, 67 insertions, 6 deletions
diff --git a/documentation/classes-and-objects.html b/documentation/classes-and-objects.html
index c8ffbb6..a38a8a6 100644
--- a/documentation/classes-and-objects.html
+++ b/documentation/classes-and-objects.html
@@ -82,11 +82,11 @@ Php::Value YourClass::example8(Php::Parameters &amp;params) const;
</p>
<p>
In the example we have used the third and seventh method forms, methods that do
- not accept any parameters, and that returns a Php::Value object. Methods
+ not accept any parameters, and that return a Php::Value object. Methods
work exactly the same as <a href="functions">regular functions</a>, with the
difference that in the methods you have (of course) access to the member
- variables of the object (and in C++ you get this for free, without
- explicitly using "this->").
+ variables of the object (and in C++ you you do not have to use "this->"
+ explicitly to access members).
</p>
<p>
To make the class accessible from PHP, you must add it to the extension
@@ -101,7 +101,7 @@ Php::Value YourClass::example8(Php::Parameters &amp;params) const;
you should specify all methods that you want to make accessible from PHP,
and finally, when all methods have been registered, you should add the
class to your extension object so that it will be accessible from PHP.
- Note that in our example we have used the C++11 std::move() function for this, so
+ Notice that in our example we have used the C++11 std::move() function for this, so
that the class object is actually <i>moved</i> into the extension object,
which is a more efficient operation than copying.
</p>
@@ -191,8 +191,12 @@ echo($counter->value()."\n");
</p>
<p>
The code above shows a PHP script that uses the native Counter class.
- The output of above script is (as you had of course expected) 3. The
- Php::ByRef class can be used too to specify parameters by reference.
+ The output of above script is (as you had of course expected) 3.
+</p>
+<p>
+ In the example code we have not shown how to use the Php::ByRef class, but
+ that works exaclty the same as in methods, so we thought that an example
+ was not really necessary.
</p>
<h2>Access modifiers</h2>
<p>
@@ -248,3 +252,60 @@ extern "C" {
because after all, your methods are called by the PHP-CPP library, and if you make
them private, the becomes invisible for the library.
</p>
+<h2>Abstract and final</h2>
+<p>
+ In the previous section we showed how to use the Php::Final and Php::Abstract
+ modifiers to create a final or abstract method. If you want to make your entire
+ class abstract or final, you can do so by using Php::FinalClass or
+ Php::AbstractClass instead of Php::Class.
+</p>
+<p>
+<pre class="language-c++"><code>
+extern "C" {
+ PHPCPP_EXPORT void *get_module() {
+ static Php::Extension myExtension("my_extension", "1.0");
+
+ // description of the class so that PHP knows which methods are accessible
+ Php::FinalClass&lt;Counter&gt; counter("Counter");
+
+ // register methods
+ ...
+
+ // return the extension
+ return myExtension;
+ }
+}
+</code></pre>
+</p>
+<p>
+ It may seem strange that you have to pass in the address of a real C++ method
+ when you mark a method as being abstract. Abstract methods do normally not
+ have an implementation, so what do you need this C++ implementation for?
+ Luckily, we also have a different way for registering abstract methods.
+</p>
+<p>
+<pre class="language-c++"><code>
+extern "C" {
+ PHPCPP_EXPORT void *get_module() {
+ static Php::Extension myExtension("my_extension", "1.0");
+
+ // description of the class so that PHP knows which methods are accessible
+ Php::Class&lt;Counter&gt; counter("Counter");
+
+ // register an abstract method
+ counter.method("myAbstractMethod", { Php::ByVal("value", Php::Type::String, true) });
+
+ // register other methods
+ ...
+
+ // return the extension
+ return myExtension;
+ }
+}
+</code></pre>
+</p>
+<p>
+ To register abstract methods, you can simply use an alternative form of the
+ Counter::method() method that does not take a pointer to a C++ method.
+</p>
+