From 09799fcd647bab68cbbaa84ca289bb3ef95184d0 Mon Sep 17 00:00:00 2001 From: Hannes Magnusson Date: Tue, 11 Dec 2007 14:53:51 +0000 Subject: [PATCH] MFB: Upgrade to the new-reference-structure - Moved the intro from reference.xml to book.xml - Change the intro ID to intro. - Moved examples into its own git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@248001 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/classobj/book.xml | 48 ++++++++ reference/classobj/constants.xml | 29 +++++ reference/classobj/examples.xml | 179 +++++++++++++++++++++++++++ reference/classobj/reference.xml | 205 +------------------------------ reference/classobj/setup.xml | 49 ++++++++ 5 files changed, 310 insertions(+), 200 deletions(-) create mode 100644 reference/classobj/book.xml create mode 100644 reference/classobj/constants.xml create mode 100644 reference/classobj/examples.xml create mode 100644 reference/classobj/setup.xml diff --git a/reference/classobj/book.xml b/reference/classobj/book.xml new file mode 100644 index 0000000000..decd2c1b97 --- /dev/null +++ b/reference/classobj/book.xml @@ -0,0 +1,48 @@ + + + + + + + Class/Object Functions + Classes/Objects + + + &reftitle.intro; + + These functions allow you to obtain information about classes + and instance objects. You can obtain the name of the class to + which an object belongs, as well as its member properties and + methods. Using these functions, you can find out not only the + class membership of an object, but also its parentage (i.e. + what class is the object class extending). + + + + &reference.classobj.setup; + &reference.classobj.constants; + &reference.classobj.examples; + &reference.classobj.reference; + + + + diff --git a/reference/classobj/constants.xml b/reference/classobj/constants.xml new file mode 100644 index 0000000000..ac10388156 --- /dev/null +++ b/reference/classobj/constants.xml @@ -0,0 +1,29 @@ + + + + + &reftitle.constants; + &no.constants; + + + + diff --git a/reference/classobj/examples.xml b/reference/classobj/examples.xml new file mode 100644 index 0000000000..9c31a719a8 --- /dev/null +++ b/reference/classobj/examples.xml @@ -0,0 +1,179 @@ + + + + + + &reftitle.examples; + + In this example, we first define a base class and an extension + of the class. The base class describes a general vegetable, + whether it is edible or not and what is its color. The subclass + Spinach adds a method to cook it and another to + find out if it is cooked. + + + + classes.inc + +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 + +?> +]]> + + + + + We then instantiate 2 objects from these classes and print out + information about them, including their class parentage. + We also define some utility functions, mainly to have a nice printout + of the variables. + + + + test_script.php + + + $val) { + 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) +{ +if (is_subclass_of($GLOBALS[$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"); +?> + +]]> + + + One important thing to note in the example above is that + the object $leafy is an instance of the class + Spinach which is a subclass of + Vegetable, + therefore the last part of the script above will output: + + + + + + + + + + diff --git a/reference/classobj/reference.xml b/reference/classobj/reference.xml index 793d3a30fe..7820ba698d 100644 --- a/reference/classobj/reference.xml +++ b/reference/classobj/reference.xml @@ -1,208 +1,13 @@ - - - + - - Class/Object Functions - Classes/Objects + + Class/Object Functions - -
- &reftitle.intro; - - These functions allow you to obtain information about classes - and instance objects. You can obtain the name of the class to - which an object belongs, as well as its member properties and - methods. Using these functions, you can find out not only the - class membership of an object, but also its parentage (i.e. - what class is the object class extending). - -
+ &reference.classobj.entities.functions; -
- &reftitle.required; - &no.requirement; -
+
-
- &reftitle.install; - &no.install; -
- -
- &reftitle.runtime; - &no.config; -
- -
- &reftitle.resources; - &no.resource; -
- -
- &reftitle.constants; - &no.constants; -
- -
- &reftitle.examples; - - In this example, we first define a base class and an extension - of the class. The base class describes a general vegetable, - whether it is edible or not and what is its color. The subclass - Spinach adds a method to cook it and another to - find out if it is cooked. - - - - classes.inc - -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 - -?> -]]> - - - - - We then instantiate 2 objects from these classes and print out - information about them, including their class parentage. - We also define some utility functions, mainly to have a nice printout - of the variables. - - - - test_script.php - - - $val) { - 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) -{ - if (is_subclass_of($GLOBALS[$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"); -?> - -]]> - - - One important thing to note in the example above is that - the object $leafy is an instance of the class - Spinach which is a subclass of - Vegetable, - therefore the last part of the script above will output: - - - - - - -
- - -&reference.classobj.entities.functions; - -
+ + + &reftitle.setup; + +
+ &reftitle.required; + &no.requirement; +
+ +
+ &reftitle.install; + &no.install; +
+ +
+ &reftitle.runtime; + &no.config; +
+ +
+ &reftitle.resources; + &no.resource; +
+ +
+ + +