-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added documentation about php.ini variables, and fixed typo in except…
…ion documentation
- Loading branch information
1 parent
a7aa076
commit 2917f09
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <phpcpp.h> | ||
|
||
/** | ||
* 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 <phpcpp.h> | ||
|
||
/** | ||
* 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> |