cvs: phpdoc-zh /reference/classobj reference.xml

From: Date: Sat, 29 Mar 2003 05:17:17 +0000
Subject: cvs: phpdoc-zh /reference/classobj reference.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-1261@lists.php.net to get a copy of this message
nio Sat Mar 29 00:17:17 2003 EDT Added files: /phpdoc-zh/reference/classobj reference.xml Log: Add file Index: phpdoc-zh/reference/classobj/reference.xml +++ phpdoc-zh/reference/classobj/reference.xml <?xml version="1.0" encoding="gb2312"?> <!-- $Revision: 1.1 $ --> <!-- $Author: nio $ --> <!-- EN-Revision: 1.6 Maintainer: nio Status: ready --> <reference id="ref.classobj"> <title>À࣯¶ÔÏóº¯Êý</title> <titleabbrev>À࣯¶ÔÏó</titleabbrev> <partintro> <section id="classobj.intro"> &reftitle.intro; <para> ÕâЩº¯ÊýÔÊÐíÄã»ñÈ¡ÀàºÍ¶ÔÏóʵÀýµÄÐÅÏ¢¡£Äã¿ÉÒÔÈ¡µÃ¶ÔÏóËùÊôµÄÀàµÄÃû×Ö£¬ÒÔ¼°ËüµÄ³ÉÔ±ÊôÐԺͷ½·¨¡£Í¨¹ýʹÓÃÕâЩº¯Êý£¬Äã²»½ö¿ÉÒÔŪÇå³þÒ»¸ö¶ÔÏóÀàµÄÈ«Ìå³ÉÔ±£¬¶øÇÒ¿ÉÒÔÖªµÀËüµÄÆðÔ´£¨ÀýÈ磬¸Ã¶ÔÏóÀàÊÇÄĸöÀàµÄÀ©Õ¹£©¡£ </para> </section> <section id="classobj.requirements"> &reftitle.required; &no.requirement; </section> <section id="classobj.installation"> &reftitle.install; &no.install; </section> <section id="classobj.configuration"> &reftitle.runtime; &no.config; </section> <section id="classobj.resources"> &reftitle.resources; &no.resource; </section> <section id="classobj.constants"> &reftitle.constants; &no.constants; </section> <section id="classobj.examples"> &reftitle.examples; <para> ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÏȶ¨ÒåÁËÒ»¸ö»ù´¡ÀàºÍÒ»¸öÀ©Õ¹Àà¡£»ù´¡ÀàÃèÊöµÄÊÇÆÕͨµÄÊ߲ˣ¨Vegetable£©£¬ËüÊÇ·ñ¿ÉʳÓã¨is_edible£©ÒÔ¼°ËüÊÇʲôÑÕÉ«£¨what_color£©¡£×ÓÀà <varname>Spinach</varname> Ôö¼ÓÁË¡°Åëµ÷¡±µÄ·½·¨£¨cook_it£©ºÍ¡°»ñÖªËüÊÇ·ñÒѱ»Åëµ÷ÁË¡±µÄ·½·¨£¨is_cooked£©¡£ </para> <para> <example> <title>classes.inc</title> <programlisting role="php"> <![CDATA[ <?php // base class with member properties and methods class Vegetable { var $edible; var $color; function Vegetable( $edible, $color="green" ) { $this->edible = $edible; $this->color = $color; } function is_edible() { return $this->edible; } function what_color() { return $this->color; } } // end of class Vegetable // extends the base class class Spinach extends Vegetable { var $cooked = false; function Spinach() { $this->Vegetable( true, "green" ); } function cook_it() { $this->cooked = true; } function is_cooked() { return $this->cooked; } } // end of class Spinach ?> ]]> </programlisting> </example> </para> <para> ½Ó×Å£¬ÎÒÃÇ´ÓÕâЩ¶ÔÏóÖд´½¨ÁËÁ½¸ö¶ÔÏóʵÀý£¬´òÓ¡³öËüÃǵÄÏà¹ØÐÅÏ¢£¬°üÀ¨ËüÃÇµÄÆðÔ´¡£ÎÒÃÇ»¹¶¨ÒåÁËһЩʵÓú¯Êý£¬ËüÃÇÖ÷ÒªÊÇΪÁËÈñäÁ¿µÄÊä³öºÃ¿´Ð©¡£ </para> <para> <example> <title>test_script.php</title> <programlisting role="php"> <![CDATA[ <pre> <?php include "classes.inc"; // utility functions function print_vars($obj) { $arr = get_object_vars($obj); while (list($prop, $val) = each($arr)) echo "\t$prop = $val\n"; } function print_methods($obj) { $arr = get_class_methods(get_class($obj)); foreach ($arr as $method) echo "\tfunction $method()\n"; } function class_parentage($obj, $class) { global $$obj; if (is_subclass_of($$obj, $class)) { echo "Object $obj belongs to class ".get_class($$obj); echo " a subclass of $class\n"; } else { echo "Object $obj does not belong to a subclass of $class\n"; } } // instantiate 2 objects $veggie = new Vegetable(true,"blue"); $leafy = new Spinach(); // print out information about objects echo "veggie: CLASS ".get_class($veggie)."\n"; echo "leafy: CLASS ".get_class($leafy); echo ", PARENT ".get_parent_class($leafy)."\n"; // show veggie properties echo "\nveggie: Properties\n"; print_vars($veggie); // and leafy methods echo "\nleafy: Methods\n"; print_methods($leafy); echo "\nParentage:\n"; class_parentage("leafy", "Spinach"); class_parentage("leafy", "Vegetable"); ?> </pre> ]]> </programlisting> </example> </para> <para> ÉϱßÀý×ÓÖÐÖØµãҪעÒâµÄÊǶÔÏó <varname>$leafy</varname> ÊÇ <classname>Spinach</classname> ÀàµÄÒ»¸öʵÀý£¬¶ø <classname>Spinach</classname> ÀàÊÇ <classname>Vegetable</classname> ÀàµÄÒ»¸ö×ÓÀ࣬Òò´ËÉϱ߽ű¾µÄ×îºó²¿·Ö½«»áÊä³ö£º </para> <para> <informalexample> <programlisting> <![CDATA[ [...] Parentage: Object leafy does not belong to a subclass of Spinach Object leafy belongs to class spinach a subclass of Vegetable ]]> </programlisting> </informalexample> </para> </section> </partintro> &reference.classobj.functions; </reference> <!-- 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 -->

« previous php.doc.zh (#1261) next »