php-doc-en/reference/reflection/extending.xml
2011-07-29 10:46:17 +00:00

100 lines
2.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="reflection.extending" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Extending</title>
<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.
</para>
<example>
<title>Extending the built-in classes</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* My Reflection_Method class
*/
class My_Reflection_Method extends ReflectionMethod
{
public $visibility = array();
public function __construct($o, $m)
{
parent::__construct($o, $m);
$this->visibility = Reflection::getModifierNames($this->getModifiers());
}
}
/**
* Demo class #1
*
*/
class T {
protected function x() {}
}
/**
* Demo class #2
*
*/
class U extends T {
function x() {}
}
// Print out information
var_dump(new My_Reflection_Method('U', 'x'));
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
object(My_Reflection_Method)#1 (3) {
["visibility"]=>
array(1) {
[0]=>
string(6) "public"
}
["name"]=>
string(1) "x"
["class"]=>
string(1) "U"
}
]]>
</screen>
</example>
<caution>
<para>
If you're overwriting the constructor, remember to call
the parent's constructor before any code you insert.
Failing to do so will result in the following:
<literal>Fatal error: Internal error: Failed to retrieve the reflection object</literal>
</para>
</caution>
</chapter>
<!-- 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
-->