File: classobj.xml

package info (click to toggle)
phpdoc 20020310-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 35,272 kB
  • ctags: 354
  • sloc: xml: 799,767; php: 1,395; cpp: 500; makefile: 200; sh: 140; awk: 51
file content (484 lines) | stat: -rw-r--r-- 14,151 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<?xml version="1.0" encoding="iso-8859-2"?>
 <reference id="ref.classobj">
  <title>Funkce pro prci s tdami/objekty</title>
  <titleabbrev>Tdy/Objekty</titleabbrev>

  <partintro>
   <sect1 id="classobj.partintro">
    <title>vod</title>
    <sect2 id="classobj.intro">
     <title>About</title>
     <para>
      Tyto funkce vm umouj zskvat informace o tdch a instancch. Mete
      zjistit nzev tdy do kter objekt pat nebo jeho promnn a metody.
      Pomoc tchto funkc mete zjistit nejen pslunost objektu k td,
      ale i jeho pedka (tj. kterou tdu tda tohoto objektu roziuje).
     </para>
    </sect2>
    <sect2 id="classobj.example">
     <title>Ukzka pouit</title>
     <para>
      V tto ukzce nejdve definujeme zkladn tdu a rozen tto tdy.
      Zkladn tda popisuje obecnou zeleninu, a u je jedl nebo ne a bez
      ohledu na jej barvu. Podtda <varname>Spenat</varname> pidv metodu
      na uvaen tto zeleniny a dal, kter zjist, jestli je vaen.
     </para>
     <para>
      <example>
       <title>classes.inc</title>
       <programlisting role="php">
&lt;?php

// zkladn tda s lenskmi promnnmi a metodami
class Zelenina {

    var $jedla;
    var $barva;

    function Zelenina( $jedla, $barva=&quot;green&quot; ) {
        $this-&gt;jedla = $jedla;
        $this-&gt;barva = $barva;
    }

    function je_jedla() {
        return $this-&gt;jedla;
    }

    function jaka_barva() {
        return $this-&gt;barva;
    }

} // konec tridy zelenina


// rozsiruje zakladni tridu
class Spenat extends Zelenina {

    var $varena = false;

    function Spenat() {
        $this-&gt;Zelenina( true, &quot;zelena&quot; );
    }

    function cook_it() {
        $this-&gt;varena = true;
    }

    function je_varena() {
        return $this-&gt;varena;
    }

} // konec tridy Spenat

?&gt;
       </programlisting>
      </example>
     </para>
     <para>
     Potom z tchto td vytvome 2 objekty a vytiskneme informace o nich, v.
     rodiovskch td. Tak definujeme nkter pomocn funkce, pedevm kvli
     pohodlnmu tisku informac.
     </para>
     <para>
      <example>
       <title>test_script.php</title>
       <programlisting role="php">
&lt;pre&gt;
&lt;?php

include &quot;classes.inc&quot;;

// pomocn funkce

function vytiskni_promenne($obj) {
    $pole = get_object_vars($obj);
    while (list($vlastnost, $hodnota) = each($pole))
        echo &quot;\t$vlastnost = $hodnota\n&quot;;
}

function vytiskni_metody($obj) {
    $pole = get_class_methods(get_class($obj));
    foreach ($pole as $metoda)
        echo &quot;\tfunction $metoda()\n&quot;;
}

function class_parentage($obj, $class) {
    global $$obj;
    if (is_subclass_of($$obj, $class)) {
        echo &quot;Objekt $obj patri do tridy &quot;.get_class($$obj);
        echo &quot; ktera je podtridou $class\n&quot;;
    } else {
        echo &quot;Objekt $obj nepatri do podtridy tridy $class\n&quot;;
    }
}

// instancujeme 2 objekty

$zeleninka = new Zelenina(true,&quot;modra&quot;);
$listnaty = new Spenat();

// vytisknout informace o obou objektech
echo &quot;zeleninka: CLASS &quot;.get_class($zeleninka).&quot;\n&quot;;
echo &quot;listnaty: CLASS &quot;.get_class($listnaty);
echo &quot;, PARENT &quot;.get_parent_class($listnaty).&quot;\n&quot;;

// vytisknout vlastnosti zeleninky
echo &quot;\nzeleninka: Vlastnosti\n&quot;;
print_vars($zeleninka);

// a metody objektu listnaty
echo &quot;\nlistnaty: Metody\n&quot;;
print_methods($listnaty);

echo &quot;\nRodic:\n&quot;;
class_parentage(&quot;listnaty&quot;, &quot;Spenat&quot;);
class_parentage(&quot;listnaty&quot;, &quot;Zelenina&quot;);
?&gt;
&lt;/pre&gt;
       </programlisting>
      </example>
     </para>
     <para>
      Je teba poznamenat, e ve ve uveden ukzce je objekt
      <varname>$listnaty</varname> instanc tdy <classname>Spenat</classname>,
      kter je podtdou tdy <classname>Zelenina</classname>, a posledn st
      ve uvedenho skriptu tud vytiskne:
     </para>
     <para>
      <informalexample>
       <programlisting>
       [...]
Rodic:
Objekt listnaty nepatri do podtridy tridy Spenat
Object listnaty patri do tridy Spenat, ktera je podtridou tridy Zelenina
       </programlisting>
      </informalexample>
     </para>
    </sect2>
   </sect1>
  </partintro>

  <refentry id="function.call-user-method">
   <refnamediv>
    <refname>call_user_method</refname>
    <refpurpose>
     Zavolat uivatelsky definouvanou metodu uritho objektu
    </refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>mixed</type><methodname>call_user_method</methodname>
      <methodparam><type>string</type><parameter>method_name</parameter></methodparam>
      <methodparam><type>object</type><parameter>obj</parameter></methodparam>
      <methodparam choice="opt"><type>mixed</type><parameter>parameter</parameter></methodparam>
      <methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
     </methodsynopsis>
    <para>
     Zavol metodu <parameter>method_name</parameter> objektu
     <parameter>obj</parameter>. Ukzka vyuit je ne, kde definujeme tdu,
     vytvome objekt a pouijeme <function>call_user_method</function> k
     nepmmu voln jej <varname>print_info</varname> metody.
     <informalexample>
      <programlisting role="php">
&lt;?php
class Country {
    var $NAME;
    var $TLD;

    function Country($name, $tld) {
        $this-&gt;NAME = $name;
        $this-&gt;TLD = $tld;
    }

    function print_info($prestr=&quot;&quot;) {
        echo $prestr.&quot;Country: &quot;.$this-&gt;NAME.&quot;\n&quot;;
        echo $prestr.&quot;Top Level Domain: &quot;.$this-&gt;TLD.&quot;\n&quot;;
    }
}

$cntry = new Country(&quot;Peru&quot;,&quot;pe&quot;);

echo &quot;* Calling the object method directly\n&quot;;
$cntry-&gt;print_info();

echo &quot;\n* Calling the same method indirectly\n&quot;;
call_user_method (&quot;print_info&quot;, $cntry, &quot;\t&quot;);
?&gt;
      </programlisting>
     </informalexample>
    </para>
    <simpara>
     Viz tak <function>call_user_func</function>.
    </simpara>
   </refsect1>
  </refentry>

  <refentry id="function.class-exists">
   <refnamediv>
    <refname>class_exists</refname>
    <refpurpose>Zjistit, jestli je tda definovna</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>bool</type><methodname>class_exists</methodname>
      <methodparam><type>string</type><parameter>class_name</parameter></methodparam>
     </methodsynopsis>
    <para>
     Tato funkce vrt &true;, pokud je tda
     <parameter>class_name</parameter> definovna, jinak &false;.
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.get-class">
   <refnamediv>
    <refname>get_class</refname>
    <refpurpose>Vrtit jmno tdy objektu</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>string</type><methodname>get_class</methodname>
      <methodparam><type>object</type><parameter>obj</parameter></methodparam>
     </methodsynopsis>
    <para>
     Tato funkce vrac nzev tdy j je objekt <parameter>obj</parameter>
     instanc.
    </para>
    <simpara>
     Viz tak <function>get_parent_class</function>,
     <function>is_subclass_of</function>
    </simpara>
   </refsect1>
  </refentry>

  <refentry id="function.get-class-methods">
   <refnamediv>
    <refname>get_class_methods</refname>
    <refpurpose>Vrtit pole nzv metod tdy</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>array</type><methodname>get_class_methods</methodname>
      <methodparam><type>string</type><parameter>class_name</parameter></methodparam>
     </methodsynopsis>
    <para>
     Tato funkce vrac pole nzv metod definovanch pro tdu specifikovanou
     argumentem <parameter>class_name</parameter>.
    </para>
    <simpara>
     Viz tak <function>get_class_vars</function>,
     <function>get_object_vars</function>
    </simpara>
   </refsect1>
  </refentry>

  <refentry id="function.get-class-vars">
   <refnamediv>
    <refname>get_class_vars</refname>
    <refpurpose>Vrtit pole defaultnch vlastnost tdy</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>array</type><methodname>get_class_vars</methodname>
      <methodparam><type>string</type><parameter>class_name</parameter></methodparam>
     </methodsynopsis>
    <para>
     Tato funkce vrac pole defaultnch vlastnost tdy
     <parameter>class_name</parameter>.
    </para>
    <simpara>
     Viz tak <function>get_class_methods</function>,
     <function>get_object_vars</function>
    </simpara>
   </refsect1>
  </refentry>

  <refentry id="function.get-declared-classes">
   <refnamediv>
    <refname>get_declared_classes</refname>
    <refpurpose>Vrtit pole nzv definovanch td</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>array</type><methodname>get_declared_classes</methodname>
      <void/>
     </methodsynopsis>
    <para>
     Tato funkce vrac pole nzv td definovanch v souasnm skriptu.
    </para>
    <note>
     <para>
      V PHP 4.0.1pl2 jsou na zatku pole vrceny jet ti dal tdy:
      <classname>stdClass</classname> (definovan v
      <filename>Zend/zend.c</filename>),
      <classname>OverloadedTestClass</classname> (definovan v
      <filename>ext/standard/basic_functions.c</filename>)
      a <classname>Directory</classname>
      (definovan v <filename>ext/standard/dir.c</filename>).
     </para>
    </note>
   </refsect1>
  </refentry>

  <refentry id="function.get-object-vars">
   <refnamediv>
    <refname>get_object_vars</refname>
    <refpurpose>Vrtit asociativn pole vlastnost objektu</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>array</type><methodname>get_object_vars</methodname>
      <methodparam><type>object</type><parameter>obj</parameter></methodparam>
     </methodsynopsis>
    <para>
     Tato funkce vrac asociativn pole definovanch vlastnost objektu
     <parameter>obj</parameter>. Promnnm deklarovanm v td j je
     <parameter>obj</parameter> instanc, kterm nebyla piazena hodnota,
     nejsou ve vrcenm poli obsaeny.
     <example>
      <title>Pouit <function>get_object_vars</function></title>
      <programlisting role="php">
&lt;?php
class Point2D {
    var $x, $y;
    var $label;

    function Point2D($x, $y) {
        $this-&gt;x = $x;
        $this-&gt;y = $y;
    }

    function setLabel($label) {
        $this-&gt;label = $label;
    }

    function getPoint() {
        return array("x" =&gt; $this-&gt;x,
                     "y" =&gt; $this-&gt;y,
                     "label" =&gt; $this-&gt;label);
    }
}

$p1 = new Point2D(1.233, 3.445);
print_r(get_object_vars($p1));
// "$label" is declared but not defined
// Array
// (
//     [x] =&gt; 1.233
//     [y] =&gt; 3.445
// )

$p1-&gt;setLabel("point #1");
print_r(get_object_vars($p1));
// Array
// (
//     [x] =&gt; 1.233
//     [y] =&gt; 3.445
//     [label] =&gt; point #1
// )

?&gt;
      </programlisting>
     </example>
    </para>
    <simpara>
     Viz tak <function>get_class_methods</function>,
     <function>get_class_vars</function>
    </simpara>
   </refsect1>
  </refentry>

  <refentry id="function.get-parent-class">
   <refnamediv>
    <refname>get_parent_class</refname>
    <refpurpose>Vrtit nzev rodiovsk tdy objektu</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>string</type><methodname>get_parent_class</methodname>
      <methodparam><type>object</type><parameter>obj</parameter></methodparam>
     </methodsynopsis>
    <para>
     Tato funkce vrac nzev rodiovsk tdy objektu
     <parameter>obj</parameter>.
    </para>
    <simpara>
     Viz tak <function>get_class</function>,
     <function>is_subclass_of</function>
    </simpara>
   </refsect1>
  </refentry>

 <refentry id="function.is-subclass-of">
   <refnamediv>
    <refname>is_subclass_of</refname>
    <refpurpose>
     Zjistit, jestli objekt pat do podtdy urit tdy
    </refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>bool</type><methodname>is_subclass_of</methodname>
      <methodparam><type>object</type><parameter>obj</parameter></methodparam>
      <methodparam><type>string</type><parameter>superclass</parameter></methodparam>
     </methodsynopsis>
    <para>
     Tato funkce vrac &true;, pokud je objekt
     <parameter>obj</parameter> instanc tdy, kter je podtdou
     <parameter>superclass</parameter>, jinak &false;.
    </para>
    <simpara>
     Viz tak <function>get_class</function>,
     <function>get_parent_class</function>
    </simpara>
   </refsect1>
  </refentry>
  <refentry id="function.method-exists">
   <refnamediv>
    <refname>method_exists</refname>
    <refpurpose>Zjistit, jestli m tda uritou metodu</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Popis</title>
     <methodsynopsis>
      <type>bool</type><methodname>method_exists</methodname>
      <methodparam><type>object</type><parameter>object</parameter></methodparam>
      <methodparam><type>string</type><parameter>method_name</parameter></methodparam>
     </methodsynopsis>
    <para>
     Tato funkce vrac &true;, pokud m
     <parameter>object</parameter> definovnu metodu
     <parameter>method_name</parameter>, jinak &false;.
    </para>
   </refsect1>
  </refentry>

 </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:
-->