tag:blogger.com,1999:blog-66644164016736270712024-02-20T18:48:54.900+07:00web developers guideParwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.comBlogger173125tag:blogger.com,1999:blog-6664416401673627071.post-79528893273837569592011-07-01T06:57:00.001+07:002011-07-01T06:58:58.318+07:00php - class_implements<div class="refnamediv">Return the interfaces which are implemented by the given class </div><h2>Description</h2>array <b>class_implements</b> ( mixed $class [, bool $autoload] )<br />
This function returns an array with the names of the interfaces that the given <i><tt>class</tt></i> and its parents implement. <br />
<h2 style="font-weight: normal;"><span style="font-size: small;"><b>Parameters</b></span></h2><div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>class</tt></i></span> </dt>
<dd>An object (class instance) or a string (class name). </dd>
<dt><span class="term"><i><tt>autoload</tt></i></span> </dt>
<dd>Whether to allow this function to load the class automatically through the <a href="http://www.blogger.com/language.oop5.autoload.html" title="Autoloading Objects">__autoload</a> magic method. Defaults to <b><tt>TRUE</tt></b>. </dd></dl></div><h2>Return Values</h2>Returns an array or <b><tt>FALSE</tt></b> on error. <br />
<h2>ChangeLog</h2><br />
<div class="informaltable"><table border="1"><colgroup> <col></col> <col></col></colgroup> <thead>
<tr> <th>Version</th> <th>Description</th></tr>
</thead> <tbody>
<tr> <td>5.1.0</td> <td>Added the option to pass the <i><tt>class</tt></i> parameter as a string. Added the <i><tt>autoload</tt></i> parameter. </td></tr>
</tbody></table></div><h2>Examples</h2><br />
<div class="example"><a href="http://www.blogger.com/post-edit.g?blogID=6664416401673627071&postID=7952889327383756959" name="id3623939"></a> <b>Example 2297. <b>class_implements()</b> example</b><br />
<br />
<div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php<br />
</span><span style="color: #007700;">interface </span><span style="color: #0000bb;">foo </span><span style="color: #007700;">{ }<br />
class </span><span style="color: #0000bb;">bar </span><span style="color: #007700;">implements </span><span style="color: #0000bb;">foo </span><span style="color: #007700;">{}<br />
</span><span style="color: #0000bb;">print_r</span><span style="color: #007700;">(</span><span style="color: #0000bb;">class_implements</span><span style="color: #007700;">(new </span><span style="color: #0000bb;">bar</span><span style="color: #007700;">));<br />
</span><span style="color: #ff8000;">// since PHP 5.1.0 you may also specify the parameter as a string</span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">print_r</span><span style="color: #007700;">(</span><span style="color: #0000bb;">class_implements</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'bar'</span><span style="color: #007700;">));<br />
<br />
<br />
function </span><span style="color: #0000bb;">__autoload</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$class_name</span><span style="color: #007700;">) {<br />
require_once </span><span style="color: #0000bb;">$class_name </span><span style="color: #007700;">. </span><span style="color: #dd0000;">'.php'</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #ff8000;">// use __autoload to load the 'not_loaded' class</span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">print_r</span><span style="color: #007700;">(</span><span style="color: #0000bb;">class_implements</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'not_loaded'</span><span style="color: #007700;">, </span><span style="color: #0000bb;">true</span><span style="color: #007700;">));<br />
</span><span style="color: #0000bb;">?></span> </span></code><br />
<br />
The above example will output something similar to:<br />
<pre>Array
(
[foo] => foo
)
Array
(
[interface_of_not_loaded] => interface_of_not_loaded
)
</pre></div></div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-78255287362105321862011-07-01T06:54:00.001+07:002011-07-01T06:55:47.283+07:00php - class_exists<div class="refnamediv">class_exists — Checks if the class has been defined</div><h2>Description</h2>bool <b>class_exists</b> ( string $class_name [, bool $autoload] )<br />
This function checks whether or not the given class has been defined. <br />
<h2>Parameters</h2><div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>class_name</tt></i></span> </dt>
<dd>The class name. The name is matched in a case-insensitive manner. </dd>
<dt><span class="term"><i><tt>autoload</tt></i></span> </dt>
<dd>Whether or not to call <a href="http://www.blogger.com/language.oop5.autoload.html" title="Autoloading Objects">__autoload</a> by default. Defaults to <b><tt>TRUE</tt></b>. </dd></dl></div><h2>Return Values</h2>Returns <b><tt>TRUE</tt></b> if <i><tt>class_name</tt></i> is a defined class, <b><tt>FALSE</tt></b> otherwise. <br />
<h2>ChangeLog</h2><br />
<div class="informaltable"><table border="1"><colgroup> <col></col> <col></col></colgroup> <thead>
<tr> <th>Version</th> <th>Description</th></tr>
</thead> <tbody>
<tr> <td>5.0.2</td> <td>No longer returns <b><tt>TRUE</tt></b> for defined interfaces. Use <a href="http://www.blogger.com/function.interface-exists.html">interface_exists()</a>. </td></tr>
<tr> <td>5.0.0</td> <td>The <i><tt>autoload</tt></i> parameter was added. </td></tr>
</tbody></table></div><h2>Examples</h2><br />
<div class="example"><a href="http://www.blogger.com/post-edit.g?blogID=6664416401673627071&postID=7825528736210532186" name="id2604823"></a> <b>Example 365. <b>class_exists()</b> example</b><br />
<div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span><span style="color: #ff8000;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #ff8000;">// Check that the class exists before trying to use it</span><span style="color: #007700;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">if (</span><span style="color: #0000bb;">class_exists</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'MyClass'</span><span style="color: #007700;">)) {<br />
</span><span style="color: #0000bb;">$myclass </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">MyClass</span><span style="color: #007700;">();<br />
}<br />
</span><span style="color: #0000bb;">?></span> </span></code></div></div><br />
<div class="example"><a href="http://www.blogger.com/post-edit.g?blogID=6664416401673627071&postID=7825528736210532186" name="id2604842"></a> <b>Example 366. <i><tt>autoload</tt></i> parameter example</b><br />
<div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">function </span><span style="color: #0000bb;">__autoload</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$class</span><span style="color: #007700;">)<br />
{<br />
include(</span><span style="color: #0000bb;">$class </span><span style="color: #007700;">. </span><span style="color: #dd0000;">'.php'</span><span style="color: #007700;">);<br />
<br />
</span><span style="color: #ff8000;">// Check to see whether the include declared the class<br />
</span><span style="color: #007700;">if (!</span><span style="color: #0000bb;">class_exists</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$class</span><span style="color: #007700;">, </span><span style="color: #0000bb;">false</span><span style="color: #007700;">)) {<br />
</span><span style="color: #0000bb;">trigger_error</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"Unable to load class: $class"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">E_USER_WARNING</span><span style="color: #007700;">);<br />
}<br />
}<br />
<br />
if (</span><span style="color: #0000bb;">class_exists</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'MyClass'</span><span style="color: #007700;">)) {<br />
</span><span style="color: #0000bb;">$myclass </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">MyClass</span><span style="color: #007700;">();<br />
}<br />
</span><span style="color: #0000bb;">?></span> </span></code></div></div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-62759296995841912972011-07-01T06:52:00.002+07:002011-07-01T06:52:42.851+07:00php - Class/Object FunctionsThese functions allow you to obtain information about classes and instance objects. You can obtain the name of the class to which an object belongs, as well as its member properties and methods. Using these functions, you can find out not only the class membership of an object, but also its parentage (i.e. what class is the object class extending). <br />
<h1><a href="" name="classobj.requirements"></a>Requirements</h1>No external libraries are needed to build this extension.<br />
<h1><a href="" name="classobj.installation"></a>Installation</h1>There is no installation needed to use these functions; they are part of the PHP core.<br />
<h1><a href="" name="classobj.configuration"></a>Runtime Configuration</h1>This extension has no configuration directives defined in <var>php.ini</var>.<br />
<h1><a href="" name="classobj.resources"></a>Resource Types</h1>This extension has no resource types defined.<br />
<h1><a href="" name="classobj.constants"></a>Predefined Constants</h1>This extension has no constants defined.<br />
<h1><a href="" name="classobj.examples"></a>Examples</h1>In this example, we first define a base class and an extension of the class. The base class describes a general vegetable, whether it is edible or not and what is its color. The subclass <var>Spinach</var> adds a method to cook it and another to find out if it is cooked. <br />
<br />
<div class="example"><a href="" name="id2604202"></a> <b>Example 363. classes.inc</b><br />
<div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php<br />
</span><span style="color: #ff8000;">// base class with member properties and methods</span><span style="color: #007700;">class </span><span style="color: #0000bb;">Vegetable </span><span style="color: #007700;">{<br />
<br />
var </span><span style="color: #0000bb;">$edible</span><span style="color: #007700;">;<br />
var </span><span style="color: #0000bb;">$color</span><span style="color: #007700;">;<br />
<br />
function </span><span style="color: #0000bb;">Vegetable</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$edible</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$color</span><span style="color: #007700;">=</span><span style="color: #dd0000;">"green"</span><span style="color: #007700;">) <br />
{<br />
</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">edible </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$edible</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">color </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$color</span><span style="color: #007700;">;<br />
}<br />
<br />
function </span><span style="color: #0000bb;">is_edible</span><span style="color: #007700;">() <br />
{<br />
return </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">edible</span><span style="color: #007700;">;<br />
}<br />
<br />
function </span><span style="color: #0000bb;">what_color</span><span style="color: #007700;">() <br />
{<br />
return </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">color</span><span style="color: #007700;">;<br />
}<br />
<br />
} </span><span style="color: #ff8000;">// end of class Vegetable<br />
<br />
// extends the base class</span><span style="color: #007700;">class </span><span style="color: #0000bb;">Spinach </span><span style="color: #007700;">extends </span><span style="color: #0000bb;">Vegetable </span><span style="color: #007700;">{<br />
<br />
var </span><span style="color: #0000bb;">$cooked </span><span style="color: #007700;">= </span><span style="color: #0000bb;">false</span><span style="color: #007700;">;<br />
<br />
function </span><span style="color: #0000bb;">Spinach</span><span style="color: #007700;">() <br />
{<br />
</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">Vegetable</span><span style="color: #007700;">(</span><span style="color: #0000bb;">true</span><span style="color: #007700;">, </span><span style="color: #dd0000;">"green"</span><span style="color: #007700;">);<br />
}<br />
<br />
function </span><span style="color: #0000bb;">cook_it</span><span style="color: #007700;">() <br />
{<br />
</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">cooked </span><span style="color: #007700;">= </span><span style="color: #0000bb;">true</span><span style="color: #007700;">;<br />
}<br />
<br />
function </span><span style="color: #0000bb;">is_cooked</span><span style="color: #007700;">() <br />
{<br />
return </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">cooked</span><span style="color: #007700;">;<br />
}<br />
<br />
} </span><span style="color: #ff8000;">// end of class Spinach<br />
</span><span style="color: #0000bb;">?></span> </span></code></div></div><br class="example-break" /> We then instantiate 2 objects from these classes and print out information about them, including their class parentage. We also define some utility functions, mainly to have a nice printout of the variables. <br />
<br />
<div class="example"><a href="" name="id2604243"></a> <b>Example 364. test_script.php</b><br />
<div class="example-contents"><code><span style="color: black;"><pre><br />
<span style="color: #0000bb;"><?php<br />
</span><span style="color: #007700;">include </span><span style="color: #dd0000;">"classes.inc"</span><span style="color: #007700;">;<br />
</span><span style="color: #ff8000;">// utility functions<br />
</span><span style="color: #007700;">function </span><span style="color: #0000bb;">print_vars</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">) <br />
{<br />
foreach (</span><span style="color: #0000bb;">get_object_vars</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">) as </span><span style="color: #0000bb;">$prop </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">$val</span><span style="color: #007700;">) {<br />
echo </span><span style="color: #dd0000;">"\t$prop = $val\n"</span><span style="color: #007700;">;<br />
}<br />
}<br />
<br />
function </span><span style="color: #0000bb;">print_methods</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">) <br />
{<br />
</span><span style="color: #0000bb;">$arr </span><span style="color: #007700;">= </span><span style="color: #0000bb;">get_class_methods</span><span style="color: #007700;">(</span><span style="color: #0000bb;">get_class</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">));<br />
foreach (</span><span style="color: #0000bb;">$arr </span><span style="color: #007700;">as </span><span style="color: #0000bb;">$method</span><span style="color: #007700;">) {<br />
echo </span><span style="color: #dd0000;">"\tfunction $method()\n"</span><span style="color: #007700;">;<br />
}<br />
}<br />
<br />
function </span><span style="color: #0000bb;">class_parentage</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$class</span><span style="color: #007700;">) <br />
{<br />
if (</span><span style="color: #0000bb;">is_subclass_of</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$GLOBALS</span><span style="color: #007700;">[</span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">], </span><span style="color: #0000bb;">$class</span><span style="color: #007700;">)) {<br />
echo </span><span style="color: #dd0000;">"Object $obj belongs to class " </span><span style="color: #007700;">. </span><span style="color: #0000bb;">get_class</span><span style="color: #007700;">($</span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">);<br />
echo </span><span style="color: #dd0000;">" a subclass of $class\n"</span><span style="color: #007700;">;<br />
} else {<br />
echo </span><span style="color: #dd0000;">"Object $obj does not belong to a subclass of $class\n"</span><span style="color: #007700;">;<br />
}<br />
}<br />
</span><span style="color: #ff8000;">// instantiate 2 objects<br />
</span><span style="color: #0000bb;">$veggie </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">Vegetable</span><span style="color: #007700;">(</span><span style="color: #0000bb;">true</span><span style="color: #007700;">, </span><span style="color: #dd0000;">"blue"</span><span style="color: #007700;">);</span><span style="color: #0000bb;">$leafy </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">Spinach</span><span style="color: #007700;">();<br />
</span><span style="color: #ff8000;">// print out information about objects</span><span style="color: #007700;">echo </span><span style="color: #dd0000;">"veggie: CLASS " </span><span style="color: #007700;">. </span><span style="color: #0000bb;">get_class</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$veggie</span><span style="color: #007700;">) . </span><span style="color: #dd0000;">"\n"</span><span style="color: #007700;">;<br />
echo </span><span style="color: #dd0000;">"leafy: CLASS " </span><span style="color: #007700;">. </span><span style="color: #0000bb;">get_class</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$leafy</span><span style="color: #007700;">);<br />
echo </span><span style="color: #dd0000;">", PARENT " </span><span style="color: #007700;">. </span><span style="color: #0000bb;">get_parent_class</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$leafy</span><span style="color: #007700;">) . </span><span style="color: #dd0000;">"\n"</span><span style="color: #007700;">;<br />
</span><span style="color: #ff8000;">// show veggie properties</span><span style="color: #007700;">echo </span><span style="color: #dd0000;">"\nveggie: Properties\n"</span><span style="color: #007700;">;</span><span style="color: #0000bb;">print_vars</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$veggie</span><span style="color: #007700;">);<br />
</span><span style="color: #ff8000;">// and leafy methods</span><span style="color: #007700;">echo </span><span style="color: #dd0000;">"\nleafy: Methods\n"</span><span style="color: #007700;">;</span><span style="color: #0000bb;">print_methods</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$leafy</span><span style="color: #007700;">);<br />
<br />
echo </span><span style="color: #dd0000;">"\nParentage:\n"</span><span style="color: #007700;">;</span><span style="color: #0000bb;">class_parentage</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"leafy"</span><span style="color: #007700;">, </span><span style="color: #dd0000;">"Spinach"</span><span style="color: #007700;">);</span><span style="color: #0000bb;">class_parentage</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"leafy"</span><span style="color: #007700;">, </span><span style="color: #dd0000;">"Vegetable"</span><span style="color: #007700;">);</span><span style="color: #0000bb;">?></span></pre></span> </code> One important thing to note in the example above is that the object <var>$leafy</var> is an instance of the class <code class="classname">Spinach</code> which is a subclass of <code class="classname">Vegetable</code>, therefore the last part of the script above will output: <br />
<pre>[...]
Parentage:
Object leafy does not belong to a subclass of Spinach
Object leafy belongs to class spinach a subclass of Vegetable
</pre></div></div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-70633530784192883262011-06-23T21:14:00.002+07:002011-06-23T21:22:27.368+07:00php - classA class is a collection of variables and functions working with these variables. Variables are defined by <var>var</var> and functions by <var>function</var>. A class is defined using the following syntax: <br />
<br />
<div class="informalexample"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">class </span><span style="color: #0000bb;">Cart </span><span style="color: #007700;">{<br />
var </span><span style="color: #0000bb;">$items</span><span style="color: #007700;">; </span><span style="color: #ff8000;">// Items in our shopping cart<br />
<br />
// Add $num articles of $artnr to the cart<br />
<br />
</span><span style="color: #007700;">function </span><span style="color: #0000bb;">add_item</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$artnr</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$num</span><span style="color: #007700;">) {<br />
</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">items</span><span style="color: #007700;">[</span><span style="color: #0000bb;">$artnr</span><span style="color: #007700;">] += </span><span style="color: #0000bb;">$num</span><span style="color: #007700;">;<br />
}<br />
<br />
</span><span style="color: #ff8000;">// Take $num articles of $artnr out of the cart<br />
<br />
</span><span style="color: #007700;">function </span><span style="color: #0000bb;">remove_item</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$artnr</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$num</span><span style="color: #007700;">) {<br />
if (</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">items</span><span style="color: #007700;">[</span><span style="color: #0000bb;">$artnr</span><span style="color: #007700;">] > </span><span style="color: #0000bb;">$num</span><span style="color: #007700;">) {<br />
</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">items</span><span style="color: #007700;">[</span><span style="color: #0000bb;">$artnr</span><span style="color: #007700;">] -= </span><span style="color: #0000bb;">$num</span><span style="color: #007700;">;<br />
return </span><span style="color: #0000bb;">true</span><span style="color: #007700;">;<br />
} elseif (</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;"> </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">items</span><span style="color: #007700;">[</span><span style="color: #0000bb;">$artnr</span><span style="color: #007700;">] == </span><span style="color: #0000bb;">$num</span><span style="color: #007700;">) {<br />
unset(</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">items</span><span style="color: #007700;">[</span><span style="color: #0000bb;">$artnr</span><span style="color: #007700;">]);<br />
return </span><span style="color: #0000bb;">true</span><span style="color: #007700;">;<br />
} else {<br />
return </span><span style="color: #0000bb;">false</span><span style="color: #007700;">;<br />
}<br />
}<br />
}</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">?></span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;"> </span> </span></code></div>This defines a class named Cart that consists of an associative array of articles in the cart and two functions to add and remove items from this cart. <br />
<div class="warning"><b class="warning">Warning</b> You can <span class="emphasis"><i>NOT</i></span> break up a class definition into multiple files. You also can <span class="emphasis"><i>NOT</i></span> break a class definition into multiple PHP blocks, unless the break is within a method declaration. The following will not work: <br />
<br />
<div class="informalexample"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">class </span><span style="color: #0000bb;">test </span><span style="color: #007700;">{</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">?><br />
<?php<br />
</span><span style="color: #007700;">function </span><span style="color: #0000bb;">test</span><span style="color: #007700;">() {<br />
print </span><span style="color: #dd0000;">'OK'</span><span style="color: #007700;">;<br />
}<br />
}</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">?></span> </span></code></div><br />
However, the following is allowed: <br />
<br />
<div class="informalexample"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">class </span><span style="color: #0000bb;">test </span><span style="color: #007700;">{<br />
function </span><span style="color: #0000bb;">test</span><span style="color: #007700;">() {</span><span style="color: #0000bb;">?></span> <span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;"><?php<br />
</span><span style="color: #007700;">print </span><span style="color: #dd0000;">'OK'</span><span style="color: #007700;">;<br />
}<br />
}</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">?></span> </span></code></div></div><br />
The following cautionary notes are valid for PHP 4. <br />
<div class="caution"><b class="caution">Caution</b> The name <var>stdClass</var> is used internally by Zend and is reserved. You cannot have a class named <var>stdClass</var> in PHP. </div><div class="caution"><b class="caution">Caution</b> The function names <var>__sleep</var> and <var>__wakeup</var> are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated with them. See below for more information. </div><div class="caution"><b class="caution">Caution</b> PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality. </div>In PHP 4, only constant initializers for <var>var</var> variables are allowed. To initialize variables with non-constant values, you need an initialization function which is called automatically when an object is being constructed from the class. Such a function is called a constructor (see below). <br />
<div class="informalexample"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">class </span><span style="color: #0000bb;">Cart </span><span style="color: #007700;">{<br />
</span><span style="color: #ff8000;">/* None of these will work in PHP 4. */<br />
</span><span style="color: #007700;">var </span><span style="color: #0000bb;">$todays_date </span><span style="color: #007700;">= </span><span style="color: #0000bb;">date</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"Y-m-d"</span><span style="color: #007700;">);<br />
var </span><span style="color: #0000bb;">$name </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$firstname</span><span style="color: #007700;">;<br />
var </span><span style="color: #0000bb;">$owner </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'Fred ' </span><span style="color: #007700;">. </span><span style="color: #dd0000;">'Jones'</span><span style="color: #007700;">;<br />
</span><span style="color: #ff8000;">/* Arrays containing constant values will, though. */<br />
</span><span style="color: #007700;">var </span><span style="color: #0000bb;">$items </span><span style="color: #007700;">= array(</span><span style="color: #dd0000;">"VCR"</span><span style="color: #007700;">, </span><span style="color: #dd0000;">"TV"</span><span style="color: #007700;">);<br />
}<br />
</span><span style="color: #ff8000;">/* This is how it should be done. */</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">class </span><span style="color: #0000bb;">Cart </span><span style="color: #007700;">{<br />
var </span><span style="color: #0000bb;">$todays_date</span><span style="color: #007700;">;<br />
var </span><span style="color: #0000bb;">$name</span><span style="color: #007700;">;<br />
var </span><span style="color: #0000bb;">$owner</span><span style="color: #007700;">;<br />
var </span><span style="color: #0000bb;">$items </span><span style="color: #007700;">= array(</span><span style="color: #dd0000;">"VCR"</span><span style="color: #007700;">, </span><span style="color: #dd0000;">"TV"</span><span style="color: #007700;">);<br />
<br />
function </span><span style="color: #0000bb;">Cart</span><span style="color: #007700;">() {<br />
</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">todays_date </span><span style="color: #007700;">= </span><span style="color: #0000bb;">date</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"Y-m-d"</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">name </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$GLOBALS</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'firstname'</span><span style="color: #007700;">];<br />
</span><span style="color: #ff8000;">/* etc. . . */<br />
</span><span style="color: #007700;">}<br />
}</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">?></span> </span></code></div>Classes are types, that is, they are blueprints for actual variables. You have to create a variable of the desired type with the <var>new</var> operator. <br />
<div class="informalexample"><br />
<code><span style="color: black;"><span style="color: #0000bb;"><?php<br />
$cart </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">Cart</span><span style="color: #007700;">;</span><span style="color: #0000bb;">$cart</span><span style="color: #007700;">-></span><span style="color: #0000bb;">add_item</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"10"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">1</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$another_cart </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">Cart</span><span style="color: #007700;">;</span><span style="color: #0000bb;">$another_cart</span><span style="color: #007700;">-></span><span style="color: #0000bb;">add_item</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"0815"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">3</span><span style="color: #007700;">);</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">?></span> </span></code></div><br />
This creates the objects <var>$cart</var> and <var>$another_cart</var>, both of the class Cart. The function add_item() of the <var>$cart</var> object is being called to add 1 item of article number 10 to the <var>$cart</var>. 3 items of article number 0815 are being added to <var>$another_cart</var>. <br />
Both, <var>$cart</var> and <var>$another_cart</var>, have functions add_item(), remove_item() and a variable items. These are distinct functions and variables. You can think of the objects as something similar to directories in a filesystem. In a filesystem you can have two different files <var>README.TXT</var>, as long as they are in different directories. Just like with directories where you'll have to type the full pathname in order to reach each file from the toplevel directory, you have to specify the complete name of the function you want to call: in PHP terms, the toplevel directory would be the global namespace, and the pathname separator would be <var>-></var>. Thus, the names <var>$cart->items</var> and <var>$another_cart->items</var> name two different variables. Note that the variable is named <var>$cart->items</var>, not <var>$cart->$items</var>, that is, a variable name in PHP has only a single dollar sign. <br />
<div class="informalexample"><br />
<code><span style="color: black;"><span style="color: #0000bb;"><?php</span><span style="color: #ff8000;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #ff8000;">// correct, single $</span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">$cart</span><span style="color: #007700;">-></span><span style="color: #0000bb;">items </span><span style="color: #007700;">= array(</span><span style="color: #dd0000;">"10" </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">1</span><span style="color: #007700;">); <br />
</span><span style="color: #ff8000;">// invalid, because $cart->$items becomes $cart->""</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">$cart</span><span style="color: #007700;">-></span><span style="color: #0000bb;">$items </span><span style="color: #007700;">= array(</span><span style="color: #dd0000;">"10" </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">1</span><span style="color: #007700;">);<br />
</span><span style="color: #ff8000;">// correct, but may or may not be what was intended:<br />
// $cart->$myvar becomes $cart->items</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">$myvar </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'items'</span><span style="color: #007700;">;</span><span style="color: #0000bb;">$cart</span><span style="color: #007700;">-></span><span style="color: #0000bb;">$myvar </span><span style="color: #007700;">= array(</span><span style="color: #dd0000;">"10" </span><span style="color: #007700;">=> </span><span style="color: #0000bb;">1</span><span style="color: #007700;">); </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">?></span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;"> </span> </span></code></div>Within a class definition, you do not know under which name the object will be accessible in your program: at the time the Cart class was written, it was unknown whether the object would be named <var>$cart</var>, <var>$another_cart</var>, or something else later. Thus, you cannot write <var>$cart->items</var> within the Cart class itself. Instead, in order to be able to access its own functions and variables from within a class, one can use the pseudo-variable <var>$this</var> which can be read as 'my own' or 'current object'. Thus, '<var>$this->items[$artnr]</var> += <var>$num</var>' can be read as 'add <var>$num</var> to the <var>$artnr</var> counter of my own items array' or 'add <var>$num</var> to the <var>$artnr</var> counter of the items array within the current object'. <br />
<blockquote><b>Note: </b>The <var>$this</var> pseudo-variable is not usually defined if the method in which it is hosted is called statically. This is not, however, a strict rule: <var>$this</var> is defined if a method is called statically from within another object. In this case, the value of <var>$this</var> is that of the calling object. This is illustrated in the following example: <br />
<div class="informalexample"><code><span style="color: black;"><span style="color: #007700;"><?php</span></span></code></div></blockquote><br />
<blockquote><div class="informalexample"><code><span style="color: black;"><span style="color: #007700;">class </span><span style="color: #0000bb;">A</span><span style="color: #007700;">{<br />
function </span><span style="color: #0000bb;">foo</span><span style="color: #007700;">(){<br />
if (isset(</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">)) {<br />
echo </span><span style="color: #dd0000;">'$this is defined ('</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">get_class</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$this</span><span style="color: #007700;">);<br />
echo </span><span style="color: #dd0000;">")\n"</span><span style="color: #007700;">;<br />
} else {<br />
echo </span><span style="color: #dd0000;">"\$this is not defined.\n"</span><span style="color: #007700;">;<br />
}<br />
}<br />
}<br />
<br />
class </span><span style="color: #0000bb;">B</span><span style="color: #007700;">{<br />
function </span><span style="color: #0000bb;">bar</span><span style="color: #007700;">()<br />
{<br />
</span><span style="color: #0000bb;">A</span><span style="color: #007700;">::</span><span style="color: #0000bb;">foo</span><span style="color: #007700;">();<br />
}<br />
}<br />
</span><span style="color: #0000bb;">$a </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">A</span><span style="color: #007700;">();</span><span style="color: #0000bb;">$a</span><span style="color: #007700;">-></span><span style="color: #0000bb;">foo</span><span style="color: #007700;">();</span><span style="color: #0000bb;">A</span><span style="color: #007700;">::</span><span style="color: #0000bb;">foo</span><span style="color: #007700;">();</span><span style="color: #0000bb;">$b </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">B</span><span style="color: #007700;">();</span><span style="color: #0000bb;">$b</span><span style="color: #007700;">-></span><span style="color: #0000bb;">bar</span><span style="color: #007700;">();</span><span style="color: #0000bb;">B</span><span style="color: #007700;">::</span><span style="color: #0000bb;">bar</span><span style="color: #007700;">();</span><span style="color: #0000bb;">?></span> </span></code> </div></blockquote><br />
<blockquote><div class="informalexample">The above example will output:</div></blockquote><blockquote><div class="informalexample"><pre>$this is defined (a)
$this is not defined.
$this is defined (b)
$this is not defined.
</pre></div></blockquote>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-7771498848724494572011-06-22T11:09:00.000+07:002011-06-22T11:09:30.642+07:00php - chunk_splitSplit a string into smaller chunks<br />
<h2>Description</h2>string <b>chunk_split</b> ( string $body [, int $chunklen [, string $end]] )<br />
Can be used to split a string into smaller chunks which is useful for e.g. converting <a href="http://www.blogger.com/function.base64-encode.html">base64_encode()</a> output to match RFC 2045 semantics. It inserts <i><tt>end</tt></i> every <i><tt>chunklen</tt></i> characters. <br />
<h2>Parameters</h2><br />
<div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>body</tt></i></span> </dt>
<dd> The string to be chunked.
</dd>
<dt><span class="term"><i><tt>chunklen</tt></i></span> </dt>
<dd> The chunk length. Defaults to 76.
</dd>
<dt><span class="term"><i><tt>end</tt></i></span> </dt>
<dd> The line ending sequence. Defaults to "\r\n". </dd></dl></div><h2>Return Values</h2>Returns the chunked string. <br />
<h2>Examples</h2><br />
<div class="example"><a href="" name="id3669423"></a> <b>Example 2383. <b>chunk_split()</b> example</b><br />
<br />
<div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span><span style="color: #ff8000;"> </span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #ff8000;">// format $data using RFC 2045 semantics</span><span style="color: #0000bb;"> </span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"> </span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;">$new_string </span><span style="color: #007700;">= </span><span style="color: #0000bb;">chunk_split</span><span style="color: #007700;">(</span><span style="color: #0000bb;">base64_encode</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$data</span><span style="color: #007700;">));</span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #007700;"><br />
</span><span style="color: #0000bb;">?></span> </span></code></div></div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-75532926666692526382011-06-22T11:07:00.000+07:002011-06-22T11:07:02.398+07:00php - chrootChange the root directory<br />
<h2>Description</h2>bool <b>chroot</b> ( string $directory )<br />
Changes the root directory of the current process to <i><tt>directory</tt></i>. <br />
This function is only available if your system supports it and you're using the CLI, CGI or Embed SAPI. Also, this function requires root privileges. <br />
<h2>Parameters</h2><br />
<div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>directory</tt></i></span> </dt>
<dd> The new directory </dd></dl></div><h2>Return Values</h2>Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure.Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-42225998714176106522011-06-22T11:04:00.002+07:002011-06-22T11:04:57.981+07:00php - chrReturn a specific character<br />
<h2>Description</h2>string <b>chr</b> ( int $ascii )<br />
Returns a one-character string containing the character specified by <i><tt>ascii</tt></i>. <br />
This function complements <a href="http://www.blogger.com/function.ord.html">ord()</a>. <br />
<h2>Parameters</h2><br />
<div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>ascii</tt></i></span> </dt>
<dd> The ascii code. </dd></dl></div><h2>Return Values</h2>Returns the specified character. <br />
<h2>Examples</h2><br />
<div class="example"><a href="" name="id3669186"></a> <b>Example 2382. <b>chr()</b> example</b><br />
<br />
<div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><br />
$str </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"The string ends in escape: "</span><span style="color: #007700;">;</span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #007700;"><br />
</span><span style="color: #0000bb;">$str </span><span style="color: #007700;">.= </span><span style="color: #0000bb;">chr</span><span style="color: #007700;">(</span><span style="color: #0000bb;">27</span><span style="color: #007700;">); </span><span style="color: #ff8000;">/* add an escape character at the end of $str */<br />
<br />
/* Often this is more useful */<br />
</span><span style="color: #0000bb;">$str </span><span style="color: #007700;">= </span><span style="color: #0000bb;">sprintf</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"The string ends in escape: %c"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">27</span><span style="color: #007700;">);</span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #007700;"><br />
</span><span style="color: #0000bb;">?></span> </span></code></div></div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-58087338820314555502011-06-22T11:01:00.001+07:002011-06-22T11:02:19.539+07:00php - chownChanges file owner<br />
<h2>Description</h2>bool <b>chown</b> ( string $filename, mixed $user )<br />
Attempts to change the owner of the file <i><tt>filename</tt></i> to user <i><tt>user</tt></i>. Only the superuser may change the owner of a file. <br />
<h2>Parameters</h2><div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>filename</tt></i></span> </dt>
<dd>Path to the file. </dd>
<dt><span class="term"><i><tt>user</tt></i></span> </dt>
<dd>A user name or number. </dd></dl></div><h2>Return Values</h2>Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure.Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-45148119644142305772011-06-18T08:24:00.002+07:002011-06-18T08:29:50.465+07:00php - chmodChanges file mode<br />
bool <b>chmod</b> ( string $filename, int $mode )<br />
<br />
Attempts to change the mode of the specified file to that given in <i><tt>mode</tt></i>.<br />
<div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>filename</tt></i></span> </dt>
<dd>Path to the file. </dd>
<dt><span class="term"><i><tt>mode</tt></i></span> </dt>
<dd>Note that <i><tt>mode</tt></i> is not automatically assumed to be an octal value, so strings (such as "g+w") will not work properly. To ensure the expected operation, you need to prefix <i><tt>mode</tt></i> with a zero (0):
<div class="informalexample"><code><span style="color: black;"><span style="color: #0000bb;"><?php </span></span></code>
<code><span style="color: black;"><span style="color: #0000bb;">chmod</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"/somedir/somefile"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">755</span><span style="color: #007700;">); </span><span style="color: #ff8000;">// decimal; probably incorrect</span></span></code>
<code></code><code><span style="color: black;"><span style="color: #0000bb;">chmod</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"/somedir/somefile"</span><span style="color: #007700;">, </span><span style="color: #dd0000;">"u+rwx,go+rx"</span><span style="color: #007700;">); </span><span style="color: #ff8000;">// string; incorrect</span></span></code>
<code>c</code><code><span style="color: black;"><span style="color: #0000bb;">hmod</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"/somedir/somefile"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0755</span><span style="color: #007700;">); </span><span style="color: #ff8000;">// octal; correct value of mode</span></span></code><code></code>
<code><span style="color: black;"><span style="color: #0000bb;">?></span></span></code>
<code></code>
<code><span style="color: black;"> </span></code></div>The <i><tt>mode</tt></i> parameter consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means that you grant execute rights, number 2 means that you make the file writeable, number 4 means that you make the file readable. Add up these numbers to specify needed rights. You can also read more about modes on Unix systems with 'man 1 chmod' and 'man 2 chmod'.
<div class="informalexample"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code>
<code><span style="color: black;"><span style="color: #ff8000;">// Read and write for owner, nothing for everybody else</span><span style="color: #0000bb;"> </span></span></code> <code><span style="color: black;"><span style="color: #0000bb;"> </span></span></code>
<code><span style="color: black;"><span style="color: #0000bb;">chmod</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"/somedir/somefile"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0600</span><span style="color: #007700;">);</span></span></code>
<code><span style="color: black;"><span style="color: #ff8000;">// Read and write for owner, read for everybody else</span><span style="color: #0000bb;"> </span></span></code> <code><span style="color: black;"><span style="color: #0000bb;"> </span></span></code>
<code><span style="color: black;"><span style="color: #0000bb;">chmod</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"/somedir/somefile"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0644</span><span style="color: #007700;">);</span></span></code>
<code><span style="color: black;"><span style="color: #ff8000;">// Everything for owner, read and execute for others</span></span></code> <code><span style="color: black;"><span style="color: #0000bb;"> </span></span></code>
<code><span style="color: black;"><span style="color: #0000bb;">chmod</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"/somedir/somefile"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0755</span><span style="color: #007700;">);</span></span></code>
<code><span style="color: black;"><span style="color: #ff8000;">// Everything for owner, read and execute for owner's group</span><span style="color: #0000bb;"> </span></span></code> <code><span style="color: black;"><span style="color: #0000bb;"> </span></span></code>
<code><span style="color: black;"><span style="color: #0000bb;">chmod</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"/somedir/somefile"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0750</span><span style="color: #007700;">);</span></span></code>
<code><span style="color: black;"><span style="color: #0000bb;">?></span> </span></code></div></dd></dl></div><h2>Return Values</h2>Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure.Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-55148117653903006152011-06-16T17:42:00.002+07:002011-06-16T19:41:23.571+07:00php - chgrpChanges file group<br />
<br />
bool <b>chgrp</b> ( string $filename, mixed $group )<br />
<br />
Attempts to change the group of the file <i><tt>filename</tt></i> to <i><tt>group</tt></i>. <br />
Only the superuser may change the group of a file arbitrarily; other users may change the group of a file to any group of which that user is a member. <br />
<h2>Parameters</h2><div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>filename</tt></i></span> </dt>
<dd>Path to the file. </dd>
<dt><span class="term"><i><tt>group</tt></i></span> </dt>
<dd>A group name or number. </dd></dl></div><h2>Return Values</h2>Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure.Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-68563743501748021882011-06-16T12:16:00.000+07:002011-06-16T12:16:21.959+07:00php - checkdnsrrCheck DNS records corresponding to a given Internet host name or IP address<br />
<h2>Description</h2>int <b>checkdnsrr</b> ( string $host [, string $type] )<br />
Searches DNS for records of type <i><tt>type</tt></i> corresponding to <i><tt>host</tt></i>. <br />
<h2>Parameters</h2><br />
<div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>host</tt></i></span> </dt>
<dd> <i><tt>host</tt></i> may either be the IP address in dotted-quad notation or the host name.
</dd>
<dt><span class="term"><i><tt>type</tt></i></span> </dt>
<dd> <i><tt>type</tt></i> may be any one of: A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT or ANY. The default is MX. </dd></dl></div><h2>Return Values</h2>Returns <b><tt>TRUE</tt></b> if any records are found; returns <b><tt>FALSE</tt></b> if no records were found or if an error occurred.Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-42509235183384510212011-06-16T12:14:00.001+07:002011-06-16T12:15:00.337+07:00php - checkdateValidate a Gregorian date<br />
<h2>Description</h2>bool <b>checkdate</b> ( int $month, int $day, int $year )<br />
Checks the validity of the date formed by the arguments. A date is considered valid if each parameter is properly defined. <br />
<h2>Parameters</h2><div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>month</tt></i></span> </dt>
<dd>The month is between 1 and 12 inclusive. </dd>
<dt><span class="term"><i><tt>day</tt></i></span> </dt>
<dd>The day is within the allowed number of days for the given <i><tt>month</tt></i>. Leap <i><tt>year</tt></i>s are taken into consideration. </dd>
<dt><span class="term"><i><tt>year</tt></i></span> </dt>
<dd>The year is between 1 and 32767 inclusive. </dd></dl></div><h2>Return Values</h2>Returns <b><tt>TRUE</tt></b> if the date given is valid; otherwise returns <b><tt>FALSE</tt></b>. <br />
<h2>Examples</h2><br />
<div class="example"><a href="http://www.blogger.com/post-edit.g?blogID=6664416401673627071&postID=4250923518338451021" name="id2651096"></a> <b>Example 430. <b>checkdate()</b> example</b><br />
<div class="example-contents"></div><div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php<br />
</span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;">var_dump</span><span style="color: #007700;">(</span><span style="color: #0000bb;">checkdate</span><span style="color: #007700;">(</span><span style="color: #0000bb;">12</span><span style="color: #007700;">, </span><span style="color: #0000bb;">31</span><span style="color: #007700;">, </span><span style="color: #0000bb;">2000</span><span style="color: #007700;">));</span><span style="color: #0000bb;"> </span></span></code></div><div class="example-contents"><br />
<code><span style="color: black;"><span style="color: #0000bb;">var_dump</span><span style="color: #007700;">(</span><span style="color: #0000bb;">checkdate</span><span style="color: #007700;">(</span><span style="color: #0000bb;">2</span><span style="color: #007700;">, </span><span style="color: #0000bb;">29</span><span style="color: #007700;">, </span><span style="color: #0000bb;">2001</span><span style="color: #007700;">));</span><span style="color: #0000bb;"> </span></span></code></div><div class="example-contents"><br />
<code><span style="color: black;"><span style="color: #0000bb;">?></span></span></code><br />
</div><div class="example-contents"><code><span style="color: black;"></span></code>The above example will output:<br />
<pre>bool(true)
bool(false)
</pre></div></div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-35088955081859972472011-06-16T12:10:00.003+07:002011-06-16T12:12:36.883+07:00php - chdirChange directory<br />
<h2>Description</h2>bool <b>chdir</b> ( string $directory )<br />
Changes PHP's current directory to <i><tt>directory</tt></i>. <br />
<h2>Parameters</h2><div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>directory</tt></i></span> </dt>
<dd>The new current directory </dd></dl></div><h2>Return Values</h2>Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure. <br />
<h2>Examples</h2><div class="example"><a href="http://www.blogger.com/post-edit.g?blogID=6664416401673627071&postID=3508895508185997247" name="id2687508"></a> <b>Example 494. <b>chdir()</b> example</b><br />
<br />
<div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;"><br />
</span><span style="color: #ff8000;">// current directory</span><span style="color: #007700;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">echo </span><span style="color: #0000bb;">getcwd</span><span style="color: #007700;">() . </span><span style="color: #dd0000;">"\n"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;"> </span></span></code><br />
<code><span style="color: black;"><span style="color: #0000bb;">chdir</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'public_html'</span><span style="color: #007700;">);</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;"><br />
</span><span style="color: #ff8000;">// current directory</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">echo </span><span style="color: #0000bb;">getcwd</span><span style="color: #007700;">() . </span><span style="color: #dd0000;">"\n"</span><span style="color: #007700;">;</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;"><br />
</span><span style="color: #0000bb;">?></span></span></code><br />
<br />
<code></code>The above example will output something similar to:<br />
<pre>/home/vincent
/home/vincent/public_html
</pre></div></div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-83225797103511700552011-06-16T11:29:00.003+07:002011-06-16T11:30:17.825+07:00php - ceilRound fractions up<br />
<h2>Description</h2>float <b>ceil</b> ( float $value )<br />
Returns the next highest integer value by rounding up <i><tt>value</tt></i> if necessary. <br />
<h2>Parameters</h2><div class="variablelist"><br />
<dl><dt><span class="term"><i><tt>value</tt></i></span> </dt>
<dd>The value to round </dd></dl></div><h2>Return Values</h2><i><tt>value</tt></i> rounded up to the next highest integer. The return value of <b>ceil()</b> is still of type <a href="http://www.blogger.com/language.types.float.html">float</a> as the value range of <a href="http://www.blogger.com/language.types.float.html">float</a> is usually bigger than that of <a href="http://www.blogger.com/language.types.integer.html">integer</a>. <br />
<h2>Examples</h2><br />
<div class="example"><a href="http://www.blogger.com/post-edit.g?blogID=6664416401673627071&postID=8322579710351170055" name="id3113107"></a> <b>Example 1125. <b>ceil()</b> example</b><br />
<br />
<div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><?php</span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #0000bb;"><br />
</span><span style="color: #007700;">echo </span><span style="color: #0000bb;">ceil</span><span style="color: #007700;">(</span><span style="color: #0000bb;">4.3</span><span style="color: #007700;">); </span><span style="color: #ff8000;">// 5</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">echo </span><span style="color: #0000bb;">ceil</span><span style="color: #007700;">(</span><span style="color: #0000bb;">9.999</span><span style="color: #007700;">); </span><span style="color: #ff8000;">// 10</span></span></code><br />
<code><span style="color: black;"><span style="color: #007700;">echo </span><span style="color: #0000bb;">ceil</span><span style="color: #007700;">(-</span><span style="color: #0000bb;">3.14</span><span style="color: #007700;">); </span><span style="color: #ff8000;">// -3</span></span></code></div><div class="example-contents"><code><span style="color: black;"><span style="color: #ff8000;"><br />
</span><span style="color: #0000bb;">?></span> </span></code></div></div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-58339109474387033292011-06-16T11:28:00.002+07:002011-06-16T11:28:35.182+07:00php - ccvs_voidPerform a full reversal on a completed transaction<br />
<h2>Description</h2>string <b>ccvs_void</b> ( string $session, string $invoice )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-30265002305780655832011-06-16T11:27:00.003+07:002011-06-16T11:27:55.521+07:00php - ccvs_textvalueGet text return value for previous function call<br />
<h2>Description</h2>string <b>ccvs_textvalue</b> ( string $session )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-70108514333567466732011-06-16T11:27:00.000+07:002011-06-16T11:27:00.507+07:00php - ccvs_statusCheck the status of an invoice<br />
<h2>Description</h2>string <b>ccvs_status</b> ( string $session, string $invoice )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-37330755462653449032011-06-16T11:25:00.002+07:002011-06-16T11:25:36.258+07:00php - ccvs_saleTransfer funds from the credit card holder to the merchant<br />
<h2>Description</h2>string <b>ccvs_sale</b> ( string $session, string $invoice )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-31273685444488126152011-06-16T11:24:00.002+07:002011-06-16T11:24:22.510+07:00php - ccvs_reversePerform a full reversal on an already-processed authorization<br />
<h2>Description</h2>string <b>ccvs_reverse</b> ( string $session, string $invoice )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-23079501270894401842011-06-16T11:22:00.002+07:002011-06-16T11:22:54.781+07:00php - ccvs_returnTransfer funds from the merchant to the credit card holder.<br />
<h2>Description</h2>string <b>ccvs_return</b> ( string $session, string $invoice )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-12863783590331809442011-06-13T09:50:00.000+07:002011-06-13T09:50:28.795+07:00php - ccvs_reportReturn the status of the background communication process<br />
<br />
<h2>Description</h2>string <b>ccvs_report</b> ( string $session, string $type )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-20624187076264179302011-06-13T09:48:00.000+07:002011-06-13T09:48:25.738+07:00php - ccvs_newCreate a new, blank transaction<br />
<br />
<h2>Description</h2>string <b>ccvs_new</b> ( string $session, string $invoice )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-22507279622364052892011-06-13T09:47:00.000+07:002011-06-13T09:47:15.978+07:00php - ccvs_lookupLook up an item of a particular type in the database #<br />
<br />
<h2>Description</h2>string <b>ccvs_lookup</b> ( string $session, string $invoice, int $inum )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-40760236955588921222011-06-13T09:45:00.000+07:002011-06-13T09:45:40.697+07:00php - ccvs_initInitialize CCVS for use<br />
<br />
<h2>Description</h2>string <b>ccvs_init</b> ( string $name )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0tag:blogger.com,1999:blog-6664416401673627071.post-35422472284228435432011-06-13T09:41:00.006+07:002011-06-13T09:43:09.414+07:00php - ccvs_doneTerminate CCVS engine and do cleanup work<br />
<br />
<h2>Description</h2>string <b>ccvs_done</b> ( string $sess )<br />
<div class="warning"><b class="warning">Warning</b> This function is currently not documented; only the argument list is available.<br />
<br />
</div>Parwantohttp://www.blogger.com/profile/00497619017490543195noreply@blogger.com0