summaryrefslogtreecommitdiff
path: root/Examples/README.md
blob: 1bb7bd5839052762b7782fe4ce1becb75a1dceee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
This directory contains a number of examples that show how to use the
PHP-CPP library. 

To run an example, there are several steps which need to be taken. 
The first step is compiling and installing the PHPCPP library. This is
done running 'make' and then 'make install' in the main directory.
The second step is compiling the C++ code and made into an extension 
usable by PHP. This is done by running 'make' and 'make install' 
in an Example directory. Do make sure you've edited the Makefile
according to your own specific directories.

The following examples are available:


Extension
---------

	The first example does nothing - it only shows how to create your
	own extension. This means your extension will be listed in the 
	output of "phpinfo()", and it is included in the array returned 
	by theget_loaded_modules() function.
	
	There are no functions or classes defined by this first example
	extension.
	
	
FunctionVoid
------------


	This second example shows how to add a function to the extension 
	and call that function from the PHP code. Adding a function to 
	your extension means that you can call it anywhere from the PHP 
	code.
	
	Furthermore, it is possible to associate your C++ function with 
	another name. This other name is then used in PHP to call the C++ 
	function, rather than the original C++ function name.
	
	Functions and/or classes defined in this example.
		- void my_function_void() Named as my_void_function()


FunctionReturnValue
-------------------


	The third example shows how to return a value from C++ to PHP. 
	Virtually any type of value can be returned to PHP from C++.
	The returned value must be returned as Php::Value, rather than
	its own type. This Php::Value can then be used in your PHP code.
	
	Because a Php::Value is always returned, there is no need to specify
	the return type of the function when adding it to your extension.
	
	Functions and/or classes defined in this example.
		- Php::Value my_return_value_function()
		

FunctionNoParameters
--------------------


	The fourth example is a combination of the second and third example.
	This example illustrates how to call a function without parameters.
	The function is added to your extension, and can then be called from
	your PHP script.
	
	The function returns a Php::Value to show that the call succeeded.
	
	Functions and/or classes defined in this example.
		- Php::Value my_no_parameters_function()
	
	
FunctionWithParameters
----------------------


	The fifth example is an example to show how several different kinds
	of parameters can used for functions. When defining the parameters for 
	your function
	
	The first option being the undefined parameters. With undefined 
	parameters, we can pass any and as many parameters as we want to 
	the function. 
	
	The second option is defining each parameter when adding the function
	to your extension. In this case we have added two Php::numericType
	parameters to the function. In 'type.h' you can find all avaiable
	types, however not every type has been implemented yet.
	
	The third option is passing a reference of a variable. Meaning when
	it is altered in the C++ code, its value will also change in the PHP
	code.
	
	Functions and/or classes defined in this example.
		- void my_with_undefined_parameters_function(Php::Parameters &params)
		- Php::Value my_with_defined_parameters_function(Php::Parameters &params)
		- void my_with_defined_parameters_reference_function(Php::Parameters &params)
		- void my_with_defined_array_parameters_function(Php::Parameters &params)
		- void my_with_defined_object_parameters_function(Php::Parameters &params)


Exceptions
----------

	The sixth example is composed of two parts, the throw exception and 
	the catch exception examples.