summaryrefslogtreecommitdiff
path: root/documentation
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-12 14:08:30 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-12 14:08:30 +0100
commit54f119f263d72f5bbeaa34d8d9b8bb4e21cd8bab (patch)
treea2c2a7b5f36c410c6e9c1de2284cd4d12ae3b6b9 /documentation
parent8e792d31f499758d3447da46dc85b68356bdbe9b (diff)
__toString is now an implicit magic method, so can be removed from the documentation about constructors and destructors
Diffstat (limited to 'documentation')
-rw-r--r--documentation/comparing-objects.html12
-rw-r--r--documentation/constructors-and-destructors.html61
2 files changed, 6 insertions, 67 deletions
diff --git a/documentation/comparing-objects.html b/documentation/comparing-objects.html
index f5c57a9..2d2c12a 100644
--- a/documentation/comparing-objects.html
+++ b/documentation/comparing-objects.html
@@ -159,11 +159,11 @@ else
</pre>
</p>
<p>
- Although we have considered to implement this comparison function as a
- magic method (for example __compare), or as a magic interface (for example
- Php::Comparable) we have decided to go for the operator&lt; approach that
- better fits the C++ language. The big advantage of this choice is that your
- objects can now also be used in many C++ STL algorithms, because they use
- operator&lt; too.
+ We have thought about implementing the comparison method as a
+ magic method (for example __compare()), or as a magic interface (for example
+ Php::Comparable). In the end we have decided to go for the operator&lt;
+ approach. It better fits the C++ language, and the big advantage is that your
+ objects can also be used in many C++ STL algorithms, because these algorithms
+ also rely on operator&lt;.
</p>
diff --git a/documentation/constructors-and-destructors.html b/documentation/constructors-and-destructors.html
index 57f82c4..d66e8a4 100644
--- a/documentation/constructors-and-destructors.html
+++ b/documentation/constructors-and-destructors.html
@@ -291,64 +291,3 @@ extern "C" {
name), while in PHP such information is required to handle reflection and
functions like get_class().
</p>
-<h2>Other magic methods</h2>
-<p>
- The __construct() and __destruct() methods are essentially regular methods
- that get automatically called by PHP in certain situations. The same is true
- for other magic methods like __toString(), __get(), __set(), et cetera. You
- can implement these methods in the same was as you would do for other methods.
- Let's add a __toString() method to our Counter class:
-</p>
-<p>
-<pre class="language-c++"><code>
-#include &lt;phpcpp.h&gt;
-
-// actual class implementation
-class Counter : public Php::Base
-{
-private:
- int _value = 0;
-
-public:
- // c++ constructor
- Counter() {}
-
- // c++ destructor
- virtual ~Counter() {}
-
- // functions to increment and decrement
- Php::Value increment() { return ++_value; }
- Php::Value decrement() { return --_value; }
- Php::Value value() const { return _value; }
-
- // convert to string
- Php::Value toString() const { return std::to_string(_value); }
-
-};
-
-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");
- counter.method("__construct", &Counter::__construct);
- counter.method("increment", &Counter::increment);
- counter.method("decrement", &Counter::decrement);
- counter.method("value", &Counter::value);
- counter.method("__toString", &Counter::toString);
-
- // add the class to the extension
- myExtension.add(std::move(counter));
-
- // return the extension
- return myExtension;
- }
-}
-</code></pre>
-</p>
-<p>
- You can also see that it is not necessary to use the same method names
- in the C++ class as in PHP. The C++ method "toString" was used, and mapped
- to the PHP function __toString().
-</p>