<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.reflection.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'reflection.extending.php',
    1 => 'Extending',
    2 => 'Extending',
  ),
  'up' => 
  array (
    0 => 'book.reflection.php',
    1 => 'Reflection',
  ),
  'prev' => 
  array (
    0 => 'reflection.examples.php',
    1 => 'Приклади',
  ),
  'next' => 
  array (
    0 => 'class.reflection.php',
    1 => 'Reflection',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/reflection/extending.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reflection.extending" class="chapter">
 <h1 class="title">Extending</h1>

 <p class="para">
  If you want to create specialized versions of the
  built-in classes (say, for creating colorized HTML when
  being exported, having easy-access member variables instead
  of methods or having utility methods), you may go ahead
  and extend them.
 </p>
 <div class="example" id="example-1">
  <p><strong>Приклад #1 Extending the built-in classes</strong></p>
  <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**<br /> * My Reflection_Method class<br /> */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">My_Reflection_Method </span><span style="color: #007700">extends </span><span style="color: #0000BB">ReflectionMethod<br /></span><span style="color: #007700">{<br />    public </span><span style="color: #0000BB">$visibility </span><span style="color: #007700">= array();<br /><br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$o</span><span style="color: #007700">, </span><span style="color: #0000BB">$m</span><span style="color: #007700">)<br />    {<br />        </span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$o</span><span style="color: #007700">, </span><span style="color: #0000BB">$m</span><span style="color: #007700">);<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">visibility </span><span style="color: #007700">= </span><span style="color: #0000BB">Reflection</span><span style="color: #007700">::</span><span style="color: #0000BB">getModifierNames</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getModifiers</span><span style="color: #007700">());<br />    }<br />}<br /><br /></span><span style="color: #FF8000">/**<br /> * Demo class #1<br /> *<br /> */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">T </span><span style="color: #007700">{<br />    protected function </span><span style="color: #0000BB">x</span><span style="color: #007700">() {}<br />}<br /><br /></span><span style="color: #FF8000">/**<br /> * Demo class #2<br /> *<br /> */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">U </span><span style="color: #007700">extends </span><span style="color: #0000BB">T </span><span style="color: #007700">{<br />    function </span><span style="color: #0000BB">x</span><span style="color: #007700">() {}<br />}<br /><br /></span><span style="color: #FF8000">// Print out information<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(new </span><span style="color: #0000BB">My_Reflection_Method</span><span style="color: #007700">(</span><span style="color: #DD0000">'U'</span><span style="color: #007700">, </span><span style="color: #DD0000">'x'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
  </div>

  <div class="example-contents"><p>Поданий вище приклад виведе щось
схоже на:</p></div>
  <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
object(My_Reflection_Method)#1 (3) {
  [&quot;visibility&quot;]=&gt;
  array(1) {
    [0]=&gt;
    string(6) &quot;public&quot;
  }
  [&quot;name&quot;]=&gt;
  string(1) &quot;x&quot;
  [&quot;class&quot;]=&gt;
  string(1) &quot;U&quot;
}
</pre></div>
  </div>
 </div>
 <div class="caution"><strong class="caution">Застереження</strong>
  <p class="para">
   If you&#039;re overwriting the constructor, remember to call
   the parent&#039;s constructor before any code you insert.
   Failing to do so will result in the following: 
   <code class="literal">Fatal error: Internal error: Failed to retrieve the reflection object</code>
  </p>
 </div>
</div>
<?php manual_footer($setup); ?>