cvs: /phpdoc/language oop.sgml /phpdoc Makefile.in chapters.ent manual.sgml /phpdoc/language control-structures.sgml

From: Date: Tue, 13 Jul 1999 18:21:50 +0000
Subject: cvs: /phpdoc/language oop.sgml /phpdoc Makefile.in chapters.ent manual.sgml /phpdoc/language control-structures.sgml
Groups: php.dev 
Request: Send a blank email to php-dev+get-8462@lists.php.net to get a copy of this message
jim Tue Jul 13 18:21:50 1999 EDT Added files: /phpdoc/language oop.sgml Modified files: /phpdoc Makefile.in chapters.ent manual.sgml /phpdoc/language control-structures.sgml Log: Move OOP stuff into its own chapter. Didn't add any information yet, just moved it to a more prominent position. Index: phpdoc/Makefile.in diff -u phpdoc/Makefile.in:1.13 phpdoc/Makefile.in:1.14 --- phpdoc/Makefile.in:1.13 Mon Jul 12 20:18:43 1999 +++ phpdoc/Makefile.in Tue Jul 13 18:21:49 1999 @@ -26,7 +26,7 @@ # +----------------------------------------------------------------------+ # -# $Id: Makefile.in,v 1.13 1999/07/13 00:18:43 jim Exp $ +# $Id: Makefile.in,v 1.14 1999/07/13 22:21:49 jim Exp $ # VPATH=@srcdir@ @@ -69,6 +69,7 @@ language/types.sgml \ language/control-structures.sgml \ language/functions.sgml \ + language/oop.sgml \ language/variables.sgml \ language/expressions.sgml Index: phpdoc/chapters.ent diff -u phpdoc/chapters.ent:1.7 phpdoc/chapters.ent:1.8 --- phpdoc/chapters.ent:1.7 Mon Jul 12 20:18:43 1999 +++ phpdoc/chapters.ent Tue Jul 13 18:21:49 1999 @@ -23,6 +23,7 @@ <!ENTITY language.operators SYSTEM "language/operators.sgml"> <!ENTITY language.functions SYSTEM "language/functions.sgml"> <!ENTITY language.control-structures SYSTEM "language/control-structures.sgml"> +<!ENTITY language.oop SYSTEM "language/oop.sgml"> <!ENTITY reference.adabas SYSTEM "functions/adabas.sgml"> <!ENTITY reference.apache SYSTEM "functions/apache.sgml"> Index: phpdoc/manual.sgml diff -u phpdoc/manual.sgml:1.10 phpdoc/manual.sgml:1.11 --- phpdoc/manual.sgml:1.10 Mon Jul 12 20:18:43 1999 +++ phpdoc/manual.sgml Tue Jul 13 18:21:49 1999 @@ -38,6 +38,7 @@ &language.operators; &language.control-structures; &language.functions; + &language.oop; </part> <part id="features"> Index: phpdoc/language/control-structures.sgml diff -u phpdoc/language/control-structures.sgml:1.2 phpdoc/language/control-structures.sgml:1.3 --- phpdoc/language/control-structures.sgml:1.2 Sun Jun 27 22:25:19 1999 +++ phpdoc/language/control-structures.sgml Tue Jul 13 18:21:49 1999 @@ -647,151 +647,6 @@ See also <function>readfile</function>, <function>require</function>, <function>virtual</function>. - <sect1 id="keyword.class"> - <title><literal>class</literal></title> - <para> - A class is a collection of variables and functions working with - these variables. A class is defined using the following syntax: - - <informalexample> - <programlisting role=php> - &lt;?php - class Cart { - var $items; // Items in our shopping cart - - // Add $num articles of $artnr to the cart - - function add_item ($artnr, $num) { - $this->items[$artnr] += $num; - } - - // Take $num articles of $artnr out of the cart - - function remove_item ($artnr, $num) { - if ($this->items[$artnr] > $num) { - $this->items[$artnr] -= $num; - return true; - } else { - return false; - } - } - } - ?> - </programlisting> - </informalexample> - - <para> - 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. - - </para><para> - Classes are types, that is, they are blueprints for actual - variables. You have to create a variables of the desired type with - the new operator. - </para> - - <informalexample> - <programlisting role=php> - $cart = new Cart; - $cart->add_item("10", 1); - </programlisting> - </informalexample> - - <para> - This creates an object $cart of the class Cart. The function - add_item() of that object is being called to add 1 item of article - number 10 to the cart. - </para><para> - Classes can be extensions of other classes. The extended or - derived class has all variables and functions of the base class - and what you add in the extended definition. This is done using - the extends keyword. - </para> - - <informalexample> - <programlisting role=php> - class Named_Cart extends Cart { - var $owner; - - function set_owner ($name) { - $this->owner = $name; - } - } - </programlisting> - </informalexample> - - <para> - This defines a class Named_Cart that has all variables and - functions of Cart plus an additional variable $owner and an - additional function set_owner(). You create a named cart the usual - way and can now set and get the carts owner. You can still use - normal cart functions on named carts: - </para> - - <informalexample> - <programlisting role=php> - $ncart = new Named_Cart; // Create a named cart - $ncart->set_owner ("kris"); // Name that cart - print $ncart->owner; // print the cart owners name - $ncart->add_item ("10", 1); // (inherited functionality from cart) - </programlisting> - </informalexample> - - <para> - Within functions of a class the variable $this means this - 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 constructor when it has the same name as the class. - </para> - - <informalexample> - <programlisting role=php> - class Auto_Cart extends Cart { - function Auto_Cart () { - $this->add_item ("10", 1); - } - } - </programlisting> - </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> - <programlisting role=php> - 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); - </programlisting> - </informalexample> - - <caution> - <simpara> - For derived classes, the constructor of the parent class is not - automatically called when the derived class's constructor is called. - </caution> - </chapter> <!-- Keep this comment at the end of the file

« previous php.dev (#8462) next »