Files
php-doc-ru/reference/reflection/extending.xml
Sergey Panteleev daef8df962 Обнуление тега Reviewed (#364)
[skip-lint]
[skip-spellcheck]
2021-11-16 13:03:53 +03:00

100 lines
2.7 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: fa6e196973e45c0013c0801e01697757f4b98426 Maintainer: aur Status: ready -->
<!-- Reviewed: no -->
<chapter xml:id="reflection.extending" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Расширение</title>
<para>
Если вам нужна специализированная версия
встроенного класса (который, например, сможет генерировать
цветной HTML при экспорте, будет иметь легкодоступные свойства
вместо методов или же какие-нибудь вспомогательные методы),
то можете просто взять и расширить его.
</para>
<example>
<title>Расширение встроенных классов</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Мой класс Reflection_Method
*/
class My_Reflection_Method extends ReflectionMethod
{
public $visibility = array();
public function __construct($o, $m)
{
parent::__construct($o, $m);
$this->visibility = Reflection::getModifierNames($this->getModifiers());
}
}
/**
* Демо-класс #1
*
*/
class T {
protected function x() {}
}
/**
* Демо-класс #2
*
*/
class U extends T {
function x() {}
}
// Выведем информацию о методе
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>
Когда вы переопределяете конструктор, не забудьте обязательно
вызвать родительский конструктор до любого добавленного вами кода.
Если так не делать, то вы можете получить сообщение об ошибке вида:
<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
-->