From 813758ad4fea24d978930d9115d4c81790faadb3 Mon Sep 17 00:00:00 2001 From: Torben Wilson Date: Thu, 10 Sep 2009 05:02:52 +0000 Subject: [PATCH] Cleaned up and made more reference-like. Split docs for properties out into its own section. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@288217 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/oop5.xml | 3 +- language/oop5/basic.xml | 159 ++++++++++++----------------------- language/oop5/properties.xml | 150 +++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+), 106 deletions(-) create mode 100644 language/oop5/properties.xml diff --git a/language/oop5.xml b/language/oop5.xml index dc9d2cbf57..12f0bd63e7 100644 --- a/language/oop5.xml +++ b/language/oop5.xml @@ -30,12 +30,13 @@ &language.oop5.basic; + &language.oop5.properties; + &language.oop5.constants; &language.oop5.autoload; &language.oop5.decon; &language.oop5.visibility; &language.oop5.paamayim-nekudotayim; &language.oop5.static; - &language.oop5.constants; &language.oop5.abstract; &language.oop5.interfaces; &language.oop5.overloading; diff --git a/language/oop5/basic.xml b/language/oop5/basic.xml index 90e48d3301..b9c73928d4 100644 --- a/language/oop5/basic.xml +++ b/language/oop5/basic.xml @@ -9,9 +9,43 @@ Every class definition begins with the keyword class, followed by a class name, - followed by a pair of curly braces which enclose the definition of - the class's members and methods. The - pseudo-variable $this is available when a + followed by a pair of curly braces which enclose the definitions + of the class's properties and methods. + + + The class name can be any valid label which is a not a + PHP reserved word. A valid class + name starts with a letter or underscore, followed by any number of + letters, numbers, or underscores. As a regular expression, it + would be expressed thus: + [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*. + + + A class may contain its + own constants, variables + (called "properties"), and functions (called "methods"). + + + Simple Class definition + +var; + } +} +?> +]]> + + + + The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but @@ -20,19 +54,8 @@ of a secondary object). - The class name can be any name which is a not a - PHP reserved word and which is a - valid label--that is, it must conform to - the PHP rules for - variable naming except that the class name has no preceding - dollar sign. - - - Here are some basic examples of class definition, object - construction, and use of the $this - pseudo-variable: - <varname>$this</varname> variable in object-oriented language + Some examples of the <varname>$this</varname> pseudo-variable foo(); + +// Note: the next line will issue a warning if E_STRICT is enabled. A::foo(); $b = new B(); $b->bar(); + +// Note: the next line will issue a warning if E_STRICT is enabled. B::bar(); ?> ]]> @@ -78,88 +106,6 @@ $this is not defined. - - Simple Class definition - -var; - } -} -?> -]]> - - - - - The default value must be a constant expression, not (for example) a - variable, a class member or a function call. - - Class members' default value - - -]]> - - - - - - There are some nice functions to handle classes and objects. You might want - to take a look at the Class/Object - Functions. - - - - - Unlike heredocs, nowdocs can be used in any static data context. - - Static data example - - -]]> - - - - - - Nowdoc support was added in PHP 5.3.0. - - @@ -233,16 +179,19 @@ object(SimpleClass)#1 (1) { extends - A class can inherit methods and members of another class by using the - extends keyword in the declaration. It is not possible to extend multiple - classes, a class can only inherit one base class. + A class can inherit the methods and properties of another class by + using the keyword extends in the class + declaration. It is not possible to extend multiple classes; a + class can only inherit from one base class. - The inherited methods and members can be overridden, unless the parent - class has defined a method as final, - by redeclaring them with the same name defined in the parent class. - It is possible to access the overridden methods or static members by - referencing them with parent:: + The inherited methods and properties can be overridden by + redeclaring them with the same name defined in the parent + class. However, if the parent class has defined a method + as final, that method + may not be overridden. It is possible to access the overridden + methods or static properties by referencing them + with parent:: Simple Class Inheritance diff --git a/language/oop5/properties.xml b/language/oop5/properties.xml new file mode 100644 index 0000000000..e7fbb8a21f --- /dev/null +++ b/language/oop5/properties.xml @@ -0,0 +1,150 @@ + + + + Properties + + + Class member variables are called "properties". You may also see + them referred to using other terms such as "attributes" or + "fields", but for the purposes of this reference we will use + "properties". They are defined by using one of the + keywords public, protected, + or private, followed by a normal variable + declaration. This declaration may include an initialization, but + this initialization must be a constant value--that is, it must be + able to be evaluated at compile time and must not depend on + run-time information in order to be evaluated. + + + See for more + information on the meanings + of public, protected, + and private. + + + + In order to maintain backward compatibility with PHP 4, PHP 5 will + still accept the use of the keyword var in + property declarations instead of (or in addition + to) public, protected, + or private. However, var is + no longer required. In versions of PHP from 5.0 to 5.1.3, the use + of var was considered deprecated and would + issue an E_STRICT warning, but since PHP + 5.1.3 it is no longer deprecated and does not issue the warning. + + + If you declare a property using var instead of + one of public, protected, + or private, then PHP 5 will treat the property + as if it had been declared as public. + + + + Within class methods the properties, constants, and methods may be + accessed by using the form $this->property + (where property is the name of the property) + unless the access is to a static property within the context of a + static class method, in which case it is accessed using the + form self::$property. See Static + Keyword for more information. + + + The pseudo-variable $this is available inside + any class method when that method is called from within an object + context. $this is a reference to the calling + object (usually the object to which the method belongs, but + possibly another object, if the method is called + statically from the context + of a secondary object). + + + + + property declarations + + +]]> + + + + + + + There are some nice functions to handle classes and objects. You + might want to take a look at + the Class/Object Functions. + + + + + Unlike + heredocs, + nowdocs + can be used in any static data context, including property + declarations. + + Example of using a nowdoc to initialize a property + + +]]> + + + + + + Nowdoc support was added in PHP 5.3.0. + + + + +