Home > Article > Backend Development > PHP INCLUDE statement contains a series of different files_PHP tutorial
We have summarized for everyone
Every time an INCLUDE is encountered, the PHP INCLUDE statement includes the specified file. So you can use the INCLUDE statement in a loop structure to include a series of different files.
The variable $this in the function means the current object. You need to use the $this->something form to access all variables or functions of the current object.
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute">cart</span><span> = </span><span class="attribute-value">new</span><span> Cart; </span></span></li> <li> <span>$cart-</span><span class="tag">></span><span>add_item("10", 1); </span> </li> </ol>
The PHP INCLUDE statement here defines a class Auto_Cart, which adds a constructor to the Cart class that sets item 10 for variable initialization every time a new operation is performed. Constructors can also have parameters, which are optional, which makes them very useful.
<ol class="dp-xml"> <li class="alt"><span><span>class Named_Cart extends Cart { </span></span></li> <li><span>var $owner; </span></li> <li class="alt"><span>function set_owner($name) { </span></li> <li> <span>$this-</span><span class="tag">></span><span class="attribute">owner</span><span> = $name; </span> </li> <li class="alt"><span>} </span></li> <li><span>} </span></li> </ol>
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute">ncart</span><span> = </span><span class="attribute-value">new</span><span> Named_Cart; </span></span></li> <li class="alt"><span><span>// Create a named cart </span></span></li> <li> <span>$ncart-</span><span class="tag">></span><span>set_owner("kris"); </span> </li> <li><span>// Name that cart </span></li> <li class="alt"> <span>print $ncart-</span><span class="tag">></span><span>owner; </span> </li> <li class="alt"><span>// print the cart owners name </span></li> <li> <span>$ncart-</span><span class="tag">></span><span>add_item("10", 1); </span> </li> <li><span>// (inherited functionality from cart) </span></li> </ol>
http://www.bkjia.com/PHPjc/445940.html
<ol class="dp-xml"> <li class="alt"><span><span>class Auto_Cart extends Cart { </span></span></li> <li><span> function Auto_Cart() { </span></li> <li class="alt"> <span> $this-</span><span class="tag">></span><span>add_item("10", 1); </span> </li> <li><span> } </span></li> <li class="alt"><span> } </span></li> </ol>www.bkjia.comtrue
<ol class="dp-xml"> <li class="alt"><span><span>class Constructor_Cart { </span></span></li> <li> <span>function Constructor_Cart<br>($</span><span class="attribute">item</span><span> = </span><span class="attribute-value">"10"</span><span>, $</span><span class="attribute">num</span><span> = </span><span class="attribute-value">1</span><span>) { </span> </li> <li class="alt"> <span>$this-</span><span class="tag">></span><span>add_item($item, $num); </span> </li> <li><span>} </span></li> <li class="alt"><span>} </span></li> <li><span> // Shop the same old boring stuff. </span></li> <li class="alt"> <span>$</span><span class="attribute">default_cart</span><span> = </span><span class="attribute-value">new</span><span> Constructor_Cart; </span> </li> <li><span>// Shop for real... </span></li> <li class="alt"> <span>$</span><span class="attribute">different_cart</span><span> = </span><span class="attribute-value">new</span><span> <br>Constructor_Cart("20", 17); </span> </li> </ol>
TechArticle