From c8ff51e13fc0a3d8fb7d1423882fa659f9cf2b3b Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Thu, 6 Mar 2014 23:39:12 +0100 Subject: update documentation --- documentation/variables.html | 56 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/documentation/variables.html b/documentation/variables.html index e6b5490..73f26bc 100644 --- a/documentation/variables.html +++ b/documentation/variables.html @@ -179,7 +179,7 @@ assoc2["z"][2] = "c";

Reading from arrays is just as simple. You can use the array access - variables for this too. + operators (square brackets) for this too.


@@ -208,17 +208,67 @@ Php::Value array2 = array1;
 array1 = 100;
 

+

+ @todo explain how to iterate over arrays +

Objects

- This section is not finished yet + Just like the Php::Array class that is an extended Php::Value that initializes + to an empty array, there also is a Php::Object class that becomes an + object when constructed. By default this is an instance of stdClass - PHP's + most simple class.

+

+


+// create empty object of type stdClass
+Php::Object object;
+
+// Php::Value is the base class, so you can assign Php::Object objects
+Php::Value value = object;
+
+// impossible, a Php::Object must always be an object
+object = "test";
+
+// object properties can be accessed with square brackets
+object["property1"] = "value1";
+object["property2"] = "value2";
 
+// to create an object of a different type, pass in the class name 
+// to the constructor with optional constructor parameters
+object = Php::Object("DateTime", "now");
 
+// methods can be called with the call() method
+std::cout << object.call("format", "Y-m-d H:i:s") << std::endl;
 
+// all these methods can be called on a Php::Value object too
+Php::Value value = Php::Object("DateTime", "now");
+std::cout << value.call("format", "Y-m-d H:i:s") << std::endl;
+

Functions

- This section is not finished yet + When a Php::Value holds a callable, you can use the () operator + to call this function or method.

+

+


+// create a string with a function name
+Php::Value date = "date";
 
+// "date" is a builtin PHP function and thus can it be called
+std::cout << date("Y-m-d H:i:s") << std::endl;
 
+// create a date-time object
+Php::Object now = Php::Object("DateTime","now");
 
+// create an array with two members, the datetime object
+// and the name of a method
+Php::Array array();
+array[0] = now;
+array[1] = "format";
+
+// an array with two members can be called too, the first
+// member is seen as the object, and the second as the
+// name of the method
+std::cout << array("Y-m-d H:i:s") << std::endl;
+
+

-- cgit v1.2.3