mirror of
https://github.com/php/doc-ru.git
synced 2025-08-16 18:22:04 +00:00
100 lines
2.7 KiB
XML
100 lines
2.7 KiB
XML
<?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
|
||
-->
|