summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-28 13:36:46 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-28 13:36:46 +0200
commit2917f09f5f4573df4ae810da1351003076adf4a8 (patch)
tree7136fcf12d41c603f4bfa69ea8be865972697bcd
parenta7aa0760a01857606ea67c5d8c63df39e0274952 (diff)
added documentation about php.ini variables, and fixed typo in exception documentation
-rw-r--r--documentation/exceptions.html2
-rw-r--r--documentation/ini.html99
2 files changed, 100 insertions, 1 deletions
diff --git a/documentation/exceptions.html b/documentation/exceptions.html
index c4f0e5c..f3938ae 100644
--- a/documentation/exceptions.html
+++ b/documentation/exceptions.html
@@ -17,7 +17,7 @@
* and that divides them. Division by zero is of course
* not permitted - it will throw an exception then
*/
-Php::Value myDiv(Php::Parameters &params)
+Php::Value myDiv(Php::Parameters &amp;params)
{
// division by zero is not permitted, throw an exception when this happens
if (params[1] == 0) throw Php::Exception("Division by zero");
diff --git a/documentation/ini.html b/documentation/ini.html
new file mode 100644
index 0000000..3d40d39
--- /dev/null
+++ b/documentation/ini.html
@@ -0,0 +1,99 @@
+<h1>Reading php.ini variables</h1>
+<p>
+ Reading settings from the php.ini file(s) is just as simple as it
+ is to obtain these settings from a regular PHP script. Inside a PHP script
+ you can use the built-in ini_get() function to read settings from the php.ini
+ file, and in your C++ extension you use the Php::ini_get() function.
+</p>
+<p>
+<pre class="language-c++"><code>#include &lt;phpcpp.h&gt;
+
+/**
+ * Simple function that is used to demonstrate how settings from the
+ * php.ini file can be read
+ */
+void myFunction()
+{
+ // read in the "output_buffering" variable from the php.ini file
+ int output_buffering = Php::ini_get("output_buffering");
+
+ // read in the "variables_order" variable
+ std::string variables_order = Php::ini_get("variables_order");
+}
+
+/**
+ * Switch to C contect so that the get_module() function can be
+ * called by the Zend engine
+ */
+extern "C" {
+ /**
+ * The get_module() startup function
+ * @return void*
+ */
+ PHPCPP_EXPORT void *get_module() {
+
+ // create extension object
+ static Php::Extension extension("my_extension", "1.0");
+
+ // export one function
+ extension.add("myFunction", myFunction);
+
+ // return a pointer to the extension object
+ return extension;
+ }
+}</code></pre>
+</p>
+<p>
+ The Php::ini_get() function returns an object that can be assigned to
+ strings, integers and floating point numbers. In the above example we have
+ used this to assign the settings directly to an integer and a std::string.
+</p>
+<p>
+ You can only retrieve <i>predefined</i> variables from the php.ini. It is thus not
+ possible to call Php::ini_get() with random strings. If you want to define
+ your own variables, you must first register them in the get_module()
+ function before you can call Php::ini_get() to retrieve the current values.
+</p>
+<p>
+<pre class="language-c++"><code>#include &lt;phpcpp.h&gt;
+
+/**
+ * Simple function that is used to demonstrate how settings from the
+ * php.ini file can be read
+ */
+void myFunction()
+{
+ // read in a variable defined for this extension
+ int var1 = Php::ini_get("my_extension.var1");
+
+ // read in a string variable
+ std::string var2 = Php::ini_get("my_extension.var2");
+}
+
+/**
+ * Switch to C contect so that the get_module() function can be
+ * called by the Zend engine
+ */
+extern "C" {
+ /**
+ * The get_module() startup function
+ * @return void*
+ */
+ PHPCPP_EXPORT void *get_module() {
+
+ // create extension object
+ static Php::Extension extension("my_extension", "1.0");
+
+ // export one function
+ extension.add("myFunction", myFunction);
+
+ // tell the PHP engine that the php.ini variables my_extension.var1
+ // and my_extension.var2 are usable
+ extension.add(Php::Ini("my_extension.var1", "default-value"));
+ extension.add(Php::Ini("my_extension.var2", 12345));
+
+ // return a pointer to the extension object
+ return extension;
+ }
+}</code></pre>
+</p>