CVS update: php3/doc/chapters
| From: | kk | Date: | Fri, 11 Sep 1998 13:34:25 +0000 |
| Subject: | CVS update: php3/doc/chapters | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-971@lists.php.net to get a copy of this message | ||
Date: Friday September 11, 1998 @ 9:34
Author: kk
Update of /repository/php3/doc/chapters
In directory asf:/u2/tmp/cvs-serv9923/doc/chapters
Modified Files:
lang-const.sgml
Log Message:
Many errata from http://ca.php.net/manual/browse-errata.php3
incorporated into the documentation source. (Errata letters A-K).
Index: php3/doc/chapters/lang-const.sgml
diff -c php3/doc/chapters/lang-const.sgml:1.23 php3/doc/chapters/lang-const.sgml:1.24
*** php3/doc/chapters/lang-const.sgml:1.23 Mon Sep 7 07:58:13 1998
--- php3/doc/chapters/lang-const.sgml Fri Sep 11 09:34:24 1998
***************
*** 476,481 ****
--- 476,486 ----
FOR(expr): ... ENDFOR; is NOT supported.
</programlisting></informalexample>
+ <para>
+ Other languages have a foreach statement to traverse an array
+ or hash. PHP uses the while statement and the <function>list<function>
+ and <function>each</function> functions for this. See the documentation
+ for these functions for an example.
<sect1 id="construct.switch">
<title>SWITCH</title>
***************
*** 797,803 ****
<programlisting role=php>
<?php
class Cart {
! var items; // Items in our shopping cart
// Add $num articles of $artnr to the cart
function add_item($artnr, $num) {
--- 802,808 ----
<programlisting role=php>
<?php
class Cart {
! var $items; // Items in our shopping cart
// Add $num articles of $artnr to the cart
function add_item($artnr, $num) {
***************
*** 880,885 ****
--- 885,924 ----
object. You have to use $this->something to access any variable or
function named something within your current object.
</para>
+
+ <para>
+ Constructors are functions in a class that are automatically
+ called when you create a new instance of a class. A function
+ becomes a constructur when it has the same name as the class.
+ </para>
+ <informalexample>
+ class Auto_Cart extends Cart {
+ function Auto_Cart() {
+ $this->add_item("10", 1);
+ }
+ }
+ </informalexample>
+
+ <para>
+ This defines a class Auto_Cart that is a Cart plus a constructor which
+ initializes the cart with one item of article number "10" each time
+ a new Auto_Cart is being made with "new". Constructors
+ can also take arguments and these arguments can be optional, which
+ makes them much more useful.
+ </para>
+ <informalexample>
+ class Constructor_Cart {
+ function Constructor_Cart($item = "10", $num = 1) {
+ $this->add_item($item, $num);
+ }
+ }
+
+ // Shop the same old boring stuff.
+ $default_cart = new Constructor_Cart;
+
+ // Shop for real...
+ $different_cart = new Constructor_Cart("20", 17);
+ </informalexample>
</sect1>
<!-- Keep this comment at the end of the file
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net