curt Sat Jul 10 15:30:37 2004 EDT Added files: /phpdoc/en/language oop5.xml /phpdoc/en/language/oop5 oop5-abstract.xml oop5-cloning.xml oop5-constants.xml oop5-decon.xml oop5-final.xml oop5-interfaces.xml oop5-iterations.xml oop5-magic.xml oop5-overloading.xml oop5-paamayim-nekudotayim.php oop5-reflection.xml oop5-static.xml oop5-visibility.xml Log: The new oop5 documentation.
http://cvs.php.net/co.php/phpdoc/en/language/oop5.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5.xml +++ phpdoc/en/language/oop5.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <chapter id="language.oop5"> <title>Classes and Objects</title>
<sect1 id="op5.intro"> <title>Introduction</title> <para> Intro to oop5 for php </para> </sect1> &language.oop5.oop5-decon; &language.oop5.oop5-visibility; <!-- Cant get this to show up right &language.oop5.oop5-paamayim-nekudotayim; --> &language.oop5.oop5-static; &language.oop5.oop5-constants; &language.oop5.oop5-abstract; &language.oop5.oop5-interfaces; &language.oop5.oop5-overloading; &language.oop5.oop5-iterations; &language.oop5.oop5-magic; &language.oop5.oop5-final; &language.oop5.oop5-cloning; &language.oop5.oop5-reflection; </chapter> <!-- 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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-abstract.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-abstract.xml +++ phpdoc/en/language/oop5/oop5-abstract.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-abstract"> <title>Object Abstraction</title> <para> PHP 5 introduces abstract classes and methods. An abstract method only declares the method's signature and does not provide an implementation. A class that contains abstract methods needs to be declared abstract. </para> <example> <title></title> <programlisting role="php"> <![CDATA[ <?php abstract class AbstractClass { abstract public function test(); } class ImplementedClass extends AbstractClass { public function test() { echo "ImplementedClass::test() called.\n"; } } $o = new ImplementedClass; $o->test(); ?> ]]> </programlisting> </example> <para> Abstract classes cannot be instantiated. Old code that has no user-defined classes or functions named 'abstract' should run without modifications. </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-cloning.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-cloning.xml +++ phpdoc/en/language/oop5/oop5-cloning.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-cloning"> <title>Object cloning</title> <para> Creating a copy of an object with fully replicated properties is not always the wanted behavior. A good example of the need for copy constructors, is if you have an object which represents a GTK window and the object holds the resource of this GTK window, when you create a duplicate you might want to create a new window with the same properties and have the new object hold the resource of the new window. Another example is if your object holds a reference to another object which it uses and when you replicate the parent object you want to create a new instance of this other object so that the replica has its own separate copy. </para> <para> An object copy is created by using the clone keyword (which calls the object's __clone() method if possible). An object's __clone() method cannot be called directly. </para> <informalexample> <programlisting> <![CDATA[ $copy_of_object = clone $object; ]]> </programlisting> </informalexample> <para> When the developer asks to create a new copy of an object, PHP 5 will check if a __clone() method has been defined or not. If not, it will call a default __clone() which will copy all of the object's properties. If a __clone() method is defined, then it will be responsible to set the necessary properties in the created object. For convenience, the engine will supply a function that imports all of the properties from the source object, so that they can start with a by-value replica of the source object, and only override properties that need to be changed. </para> <example> <title>Cloning an object</title> <programlisting role="php"> <![CDATA[ <?php class MyCloneable { static $id = 0; function MyCloneable() { $this->id = self::$id++; } function __clone() { $this->address = "New York"; $this->id = self::$id++; } } $obj = new MyCloneable(); $obj->name = "Hello"; $obj->address = "Tel-Aviv"; print $obj->id . "\n"; $obj_cloned = clone $obj; print $obj_cloned->id . "\n"; print $obj_cloned->name . "\n"; print $obj_cloned->address . "\n"; ?> ]]> </programlisting> </example> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-constants.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-constants.xml +++ phpdoc/en/language/oop5/oop5-constants.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-constants"> <title>Object Constants</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-decon.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-decon.xml +++ phpdoc/en/language/oop5/oop5-decon.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-decon"> <title>Constructors and Destructors</title> <sect2 id="oop5-decon-constructor"> <title>Constructor</title> <para> PHP 5 allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used. </para> <note> <simpara> Parent constructors are not called implicitly. In order to run a parent constructor, a call to <function>parent::__construct()</function> is required. </simpara> </note> <example> <title>using new unified constructors</title> <programlisting role="php"> <![CDATA[ <?php class BaseClass { function __construct() { print "In BaseClass constructor\n"; } } class SubClass extends BaseClass { function __construct() { parent::__construct(); print "In SubClass constructor\n"; } } $obj = new BaseClass(); $obj = new SubClass(); ?> ]]> </programlisting> </example> <para> For backwards compatibility, if PHP 5 cannot find a <function>__construct</function> function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named <function>__construct</function> which was used for different semantics. </para> </sect2> <sect2 id="oop5-decon-destructor"> <title>Destructor</title> <para> PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as Java: When the last reference to an object is destroyed the object's destructor, which is a class method named <function>__destruct</function> that receives no parameters, is called before the object is freed from memory. </para> <example> <title>Destructor Example</title> <programlisting role="php"> <![CDATA[ <?php class MyDestructableClass { function __construct() { print "In constructor\n"; $this->name = "MyDestructableClass"; } function __destruct() { print "Destroying " . $this->name . "\n"; } } $obj = new MyDestructableClass(); ?> ]]> </programlisting> </example> <para> Like constructors, parent destructors will not be called implicitly by the engine. In order to run a parent destructor, one would have to explicitly call <function>parent::__destruct</function> in the destructor body. </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-final.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-final.xml +++ phpdoc/en/language/oop5/oop5-final.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-final"> <title>Final Keyword</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-interfaces.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-interfaces.xml +++ phpdoc/en/language/oop5/oop5-interfaces.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-interfaces"> <title>Object Interfaces</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-iterations.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-iterations.xml +++ phpdoc/en/language/oop5/oop5-iterations.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-iterations"> <title>Object Iteration</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-magic.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-magic.xml +++ phpdoc/en/language/oop5/oop5-magic.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-magic"> <title>Magic Methods</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-overloading.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-overloading.xml +++ phpdoc/en/language/oop5/oop5-overloading.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-overloading"> <title>Overloading</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-paamayim-nekudotayim.php?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-paamayim-nekudotayim.php +++ phpdoc/en/language/oop5/oop5-paamayim-nekudotayim.php <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-paamayim-nekudotayim"> <title>::</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-reflection.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-reflection.xml +++ phpdoc/en/language/oop5/oop5-reflection.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-reflection"> <title>Reflection</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-static.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-static.xml +++ phpdoc/en/language/oop5/oop5-static.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-static"> <title>Static</title> <para> . </para> </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 --> http://cvs.php.net/co.php/phpdoc/en/language/oop5/oop5-visibility.xml?r=1.1&p=1 Index: phpdoc/en/language/oop5/oop5-visibility.xml +++ phpdoc/en/language/oop5/oop5-visibility.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <sect1 id="oop5-visibility"> <title>Visibility</title> <para> The visibility of a member or method can be defined by prefixing the declaration with the keywords: public, protected or private. Public declared items can be allow access to any caller. Protected limits access access to only classes inherited. Protected limits visiblity only to the class that defines the item. </para> <sect2 id="oop5-visiblity-members"> <title>Members Visibility</title> <para> Class members must be defined with public, private, or private. </para> <example> <title>Member declaration</title> <programlisting role="php"> <![CDATA[ <?php class MyClass { public $public = "MyClass::public!\n"; protected $protected = "MyClass::Protected!\n"; protected $protected2 = "MyClass::Protected2!\n"; private $private = "MyClass::private!\n"; function printHello() { print "MyClass::printHello() " . $this->private; print "MyClass::printHello() " . $this->protected; print "MyClass::printHello() " . $this->protected2; } } class MyClass2 extends MyClass { protected $protected = "MyClass2::protected!\n"; function printHello() { MyClass::printHello(); print "MyClass2::printHello() " . $this->public; print "MyClass2::printHello() " . $this->protected; print "MyClass2::printHello() " . $this->protected2; /* Will result in a Fatal Error: */ //print "MyClass2::printHello() " . $this->private; /* Fatal Error */ } } $obj = new MyClass(); print "Main:: " . $obj->public; //print $obj->private; /* Fatal Error */ //print $obj->protected; /* Fatal Error */ //print $obj->protected2; /* Fatal Error */ $obj->printHello(); /* Should print */ $obj2 = new MyClass2(); print "Main:: " . $obj2->private; /* Undefined */ //print $obj2->protected; /* Fatal Error */ //print $obj2->protected2; /* Fatal Error */ $obj2->printHello(); ?> ]]> </programlisting> </example> <note> <simpara> The use PHP 4 use of declaring a variable with the keyword 'var' is no longer valid for PHP 5 objects. For compatiblity a variable declared in php will be assumed with public visiblity, and a E_STRICT warning will be issued. </simpara> </note> </sect2> <sect2 id="oop5-visiblity-methods"> <title>Method Visibility</title> <para> . </para> </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 -->