From e7736a8d65765f7500e06af400457cca95ceae45 Mon Sep 17 00:00:00 2001
From: Clyde Semeleer
-
-void example1();
+void example1();
void example2(Php::Parameters ¶ms);
Php::Value example3();
-Php::Value example4(Php::Parameters ¶ms);
-
+Php::Value example4(Php::Parameters ¶ms);
+
These function signatures show you two important PHP-CPP classes, the Php::Value class and the Php::Parameters class. The Php::Value class is a @@ -29,8 +29,7 @@ Php::Value example4(Php::Parameters ¶ms); name by which the function becomes callable from within your PHP scripts.
-
-#include <phpcpp.h>
+#include <phpcpp.h>
#include <iostream>
void myFunction()
@@ -44,8 +43,7 @@ extern "C" {
extension.add("myFunction", myFunction);
return extension;
}
-}
-
+}
It is not difficult to imagine what the above code does. If you enable @@ -59,8 +57,7 @@ extern "C" { want to return a value from your function?
-
-#include <phpcpp.h>
+#include <phpcpp.h>
#include <stdlib.h>
Php::Value myFunction()
@@ -81,8 +78,7 @@ extern "C" {
extension.add("myFunction", myFunction);
return extension;
}
-}
-
+}
Is that cool or not? In PHP it is perfectly legal to make functions that @@ -95,11 +91,9 @@ extern "C" { simple PHP script.
-
-<?php
+<?php
for ($i=0; $i<10; $i++) echo(myFunction()."\n");
-?>
-
+?>
The possible output of this script could for example be: @@ -125,8 +119,7 @@ string The following example function that takes a variable number of parameters, and sums up the integer value of each of the parameters:
-
-#include <phpcpp.h>
+#include <phpcpp.h>
Php::Value sum_everything(Php::Parameters ¶meters)
{
@@ -141,8 +134,7 @@ extern "C" {
extension.add("sum_everything", sum_everything);
return extension;
}
-}
-
+}
The Php::Parameters class is in reality nothing less than a std::vector filled with Php::Value objects - and you can thus iterate over it. In the @@ -163,11 +155,9 @@ extern "C" { PHP script. Let's run a test.
-
-<?php
+<?php
echo(sum_everything(10,"100",20)."\n");
-?>
-
+?>
The output of the above script is, of course, 130. The "100" string variable diff --git a/documentation/your-first-extension.html b/documentation/your-first-extension.html index 02d85cd..cebc44f 100644 --- a/documentation/your-first-extension.html +++ b/documentation/your-first-extension.html @@ -196,8 +196,7 @@ extension=yourextension.so all your functions and classes to it.
-
-#include <phpcpp.h>
+#include <phpcpp.h>
/**
* tell the compiler that the get_module is a pure C function
@@ -222,8 +221,7 @@ extern "C" {
// return the extension
return extension;
}
-}
-
+}
-
\ No newline at end of file
+
--
cgit v1.2.3