Skip to content

Commit

Permalink
added documentation about php.ini variables, and fixed typo in except…
Browse files Browse the repository at this point in the history
…ion documentation
  • Loading branch information
EmielBruijntjes committed Apr 28, 2014
1 parent a7aa076 commit 2917f09
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion documentation/exceptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1>Exceptions</h1>
* 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");
Expand Down
99 changes: 99 additions & 0 deletions documentation/ini.html
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 &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>

0 comments on commit 2917f09

Please sign in to comment.