File: properties.xml

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (150 lines) | stat: -rw-r--r-- 4,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 297028 $ -->
 <sect1 xml:id="language.oop5.properties" xmlns="http://docbook.org/ns/docbook">
  <title>Properties</title>

  <para>
   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 <literal>public</literal>, <literal>protected</literal>,
   or <literal>private</literal>, 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.
  </para>
  <para>
   See <xref linkend="language.oop5.visibility" /> for more
   information on the meanings
   of <literal>public</literal>, <literal>protected</literal>,
   and <literal>private</literal>.
  </para>
  <note>
   <para>
    In order to maintain backward compatibility with PHP 4, PHP 5 will
    still accept the use of the keyword <literal>var</literal> in
    property declarations instead of (or in addition
    to) <literal>public</literal>, <literal>protected</literal>,
    or <literal>private</literal>. However, <literal>var</literal> is
    no longer required. In versions of PHP from 5.0 to 5.1.3, the use
    of <literal>var</literal> was considered deprecated and would
    issue an <constant>E_STRICT</constant> warning, but since PHP
    5.1.3 it is no longer deprecated and does not issue the warning.
   </para>
   <para>
    If you declare a property using <literal>var</literal> instead of
    one of <literal>public</literal>, <literal>protected</literal>,
    or <literal>private</literal>, then PHP 5 will treat the property
    as if it had been declared as <literal>public</literal>.
   </para>
  </note>
  <para>
   Within class methods the properties, constants, and methods may be
   accessed by using the form <varname>$this-&gt;property</varname>
   (where <literal>property</literal> 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 <varname>self::$property</varname>. See <link linkend="language.oop5.static">Static
   Keyword</link> for more information.
  </para>
  <para>
   The pseudo-variable <varname>$this</varname> is available inside
   any class method when that method is called from within an object
   context. <varname>$this</varname> is a reference to the calling
   object (usually the object to which the method belongs, but
   possibly another object, if the method is called
   <link linkend="language.oop5.static">statically</link> from the context
   of a secondary object).
  </para>

  <para>
   <example>
    <title>property declarations</title>
    <programlisting role="php">
<![CDATA[
<?php
class SimpleClass
{
   // invalid property declarations:
   public $var1 = 'hello ' . 'world';
   public $var2 = <<<EOD
hello world
EOD;
   public $var3 = 1+2;
   public $var4 = self::myStaticMethod();
   public $var5 = $myVar;

   // valid property declarations:
   public $var6 = myConstant;
   public $var7 = array(true, false);

   // This is allowed only in PHP 5.3.0 and later.
   public $var8 = <<<'EOD'
hello world
EOD;
}
?>
]]>
    </programlisting>   
   </example>
  </para>

  <note>
   <para>
    There are some nice functions to handle classes and objects. You
    might want to take a look at
    the <link linkend="ref.classobj">Class/Object Functions</link>.
   </para>
  </note>

  <para>
   Unlike
   <link linkend="language.types.string.syntax.heredoc">heredocs</link>, 
   <link linkend="language.types.string.syntax.nowdoc">nowdocs</link>
   can be used in any static data context, including property
   declarations.
   <example>
    <title>Example of using a nowdoc to initialize a property</title>
    <programlisting role="php">
<![CDATA[
<?php
class foo {
   // As of PHP 5.3.0
   public $bar = <<<'EOT'
bar
EOT;
}
?>
]]>
    </programlisting>
   </example>
  </para>
  <note>
   <para>
    Nowdoc support was added in PHP 5.3.0.
   </para>
  </note>
 </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:"~/.phpdoc/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
-->