svn: /phpdoc/en/trunk/language/ oop5/inheritance.xml oop5.xml
| From: | Brandon Savage | Date: | Tue, 22 Sep 2009 21:33:16 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ oop5/inheritance.xml oop5.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4966@lists.php.net to get a copy of this message | ||
brandon Tue, 22 Sep 2009 21:33:16 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=288590
Log:
Adding information and example on inheritance as an OOP principle, per PHP-DOC discussion.
Changed paths:
A phpdoc/en/trunk/language/oop5/inheritance.xml
U phpdoc/en/trunk/language/oop5.xml
Added: phpdoc/en/trunk/language/oop5/inheritance.xml
===================================================================
--- phpdoc/en/trunk/language/oop5/inheritance.xml (rev 0)
+++ phpdoc/en/trunk/language/oop5/inheritance.xml 2009-09-22 21:33:16 UTC (rev 288590)
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- $Revision: 288440 $ -->
+ <sect1 xml:id="language.oop5.inheritance" xmlns="http://docbook.org/ns/docbook">
+ <title>Object Inheritance</title>
+ <para>
+ Inheritance is a well-esablished programming principle, and PHP makes use
+ of this principle in its object model. This principle will affect the way
+ many classes and objects relate to one another.
+ </para>
+ <para>
+ For example, when you extend a class, the subclass inherits all of the
+ public and protected methods from the parent class. Unless a class overrides
+ those methods, they will retain their original functionality.
+ </para>
+ <para>
+ This is useful for defining and abstracting functionality, and permits the
+ implementation of additional functionality in similar objects without the
+ need to reimplement all of the shared functionality.
+ </para>
+ <sect2 xml:id="language.oop5.inheritance.examples">
+ <example xml:id="language.oop5.inheritance.examples.ex1">
+ <title>Inheritance Example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+
+class foo
+{
+ public function printItem($string)
+ {
+ echo 'Foo: ' . $string . PHP_EOL;
+ }
+
+ public function printPHP()
+ {
+ echo 'PHP is great.' . PHP_EOL;
+ }
+}
+
+class bar extends foo
+{
+ public function printItem($string)
+ {
+ echo 'Bar: ' . $string . PHP_EOL;
+ }
+}
+
+$foo = new foo();
+$bar = new bar();
+$foo->printItem('baz'); // Output: 'Foo: baz'
+$foo->printPHP(); // Output: 'PHP is great'
+$bar->printItem('baz'); // Output: 'Bar: baz'
+$bar->printPHP(); // Output: 'PHP is great'
+
+?>
+]]>
+ </programlisting>
+ </example>
+ </sect2>
+ </sect1>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+indent-tabs-mode:nil
+sgml-parent-document:nil
+sgml-default-dtd-file:"../../manual.ced"
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+vim600: syn=xml fen fdm=syntax fdl=2 si
+vim: et tw=78 syn=sgml
+vi: ts=1 sw=1
+-->
Modified: phpdoc/en/trunk/language/oop5.xml
===================================================================
--- phpdoc/en/trunk/language/oop5.xml 2009-09-22 19:20:44 UTC (rev 288589)
+++ phpdoc/en/trunk/language/oop5.xml 2009-09-22 21:33:16 UTC (rev 288590)
@@ -35,6 +35,7 @@
&language.oop5.autoload;
&language.oop5.decon;
&language.oop5.visibility;
+ &language.oop5.inheritance;
&language.oop5.paamayim-nekudotayim;
&language.oop5.static;
&language.oop5.abstract;