<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.xml.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.xml-set-external-entity-ref-handler.php',
    1 => 'xml_set_external_entity_ref_handler',
    2 => '设置外部实体引用处理程序',
  ),
  'up' => 
  array (
    0 => 'ref.xml.php',
    1 => 'XML 解析器函数',
  ),
  'prev' => 
  array (
    0 => 'function.xml-set-end-namespace-decl-handler.php',
    1 => 'xml_set_end_namespace_decl_handler',
  ),
  'next' => 
  array (
    0 => 'function.xml-set-notation-decl-handler.php',
    1 => 'xml_set_notation_decl_handler',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/xml/functions/xml-set-external-entity-ref-handler.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.xml-set-external-entity-ref-handler" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">xml_set_external_entity_ref_handler</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">xml_set_external_entity_ref_handler</span> &mdash; <span class="dc-title">设置外部实体引用处理程序</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.xml-set-external-entity-ref-handler-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>xml_set_external_entity_ref_handler</strong></span>(<span class="methodparam"><span class="type"><a href="class.xmlparser.php" class="type XMLParser">XMLParser</a></span> <code class="parameter">$parser</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span> <code class="parameter">$handler</code></span>): <span class="type"><a href="language.types.singleton.php" class="type true">true</a></span></div>

  <p class="para rdfs-comment">
   为 XML 解析器 <code class="parameter">parser</code> 设置外部实体引用处理函数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.xml-set-external-entity-ref-handler-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
 <dt><code class="parameter">parser</code></dt>
 <dd>
  <p class="para">
   XML 解析器。
  </p>
 </dd>

    
     <dt><code class="parameter">handler</code></dt>
     <dd>
      <p class="para">
 如果传递 <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>，处理程序将重置为其默认状态。
 <div class="warning"><strong class="warning">警告</strong>
  <p class="simpara">
    空字符串也可以重置处理程序，然而自 PHP 8.4.0 起已弃用。
  </p>
 </div>
</p>
<p class="para">
 如果 <code class="parameter">handler</code> 是 <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span>，设置的 callable 将作为处理程序。
</p>
<p class="para">
 如果 <code class="parameter">handler</code> 是 <span class="type"><a href="language.types.string.php" class="type string">string</a></span>，它可以是 <span class="function"><a href="function.xml-set-object.php" class="function">xml_set_object()</a></span>
 设置的对象的方法名称。
 <div class="warning"><strong class="warning">警告</strong>
  <p class="simpara">
   自 PHP 8.4.0 起弃用。
  </p>
 </div>
</p>
<div class="warning"><strong class="warning">警告</strong>
 <p class="simpara">
  自 PHP 8.4.0 起，在设置处理程序时会检测 callable 是否有效，而不是在调用时检测。这意味着在将字符串方法名设置为
  callback 之前必须调用 <span class="function"><a href="function.xml-set-object.php" class="function">xml_set_object()</a></span>。然而，由于此行为自 PHP 8.4.0
  起也已弃用，因此建议为该方法使用适当的<span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span>。
 </p>
</div>

      <p class="para">
       处理程序的签名必须是：
       <div class="methodsynopsis dc-description"><span class="methodname"><span class="replaceable">handler</span></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.xmlparser.php" class="type XMLParser">XMLParser</a></span> <code class="parameter">$parser</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$open_entity_names</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span> <code class="parameter">$base</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$system_id</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span> <code class="parameter">$public_id</code></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

       <dl>
        
 <dt><code class="parameter">parser</code></dt>
 <dd>
  <span class="simpara">
   XML 解析器调用的处理程序。
  </span>
 </dd>

        
         <dt><code class="parameter">open_entity_names</code></dt>
         <dd>
          <span class="simpara">
           为该实体的解析开放的实体名列表（包括被指向的实体名），这些实体名由空格隔开。
          </span>
         </dd>
        
        
         <dt><code class="parameter">base</code></dt>
         <dd>
          <span class="simpara">
          这个参数是解析外部实体的系统标识符（<code class="parameter">system_id</code>）的基础。
          </span>
         </dd>
        
        
         <dt><code class="parameter">system_id</code></dt>
         <dd>
          <span class="simpara">
           在实体定义声明中指定的系统标识符。
          </span>
         </dd>
        
        
         <dt><code class="parameter">public_id</code></dt>
         <dd>
          <span class="simpara">
           在实体定义声明中指定的公共标识符，如果未指定任何标识符，则该字符串为空。公共标识符中的空格将按照 XML 的要求被正常化。
          </span>
         </dd>
        
       </dl>
      </p>
      <p class="para">
       如果实体已经处理，则处理程序应返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>，否则返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。当返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> 时，XML
       解析器将停止解析并且 <span class="function"><a href="function.xml-get-error-code.php" class="function">xml_get_error_code()</a></span> 将返回
       <strong><code><a href="xml.constants.php#constant.xml-error-external-entity-handling">XML_ERROR_EXTERNAL_ENTITY_HANDLING</a></code></strong>。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.xml-set-external-entity-ref-handler-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   总是返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.xml-set-external-entity-ref-handler-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.4.0</td>
 <td>
  现已弃用传递非 <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> 的 <span class="type"><a href="language.types.string.php" class="type string">string</a></span> 到 <code class="parameter">handler</code>，为方法使用适当的
  callable 或者使用 <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> 来重置处理程序。
 </td>
</tr>

<tr>
 <td>8.4.0</td>
 <td>
  现在设置处理程序时会检测 <code class="parameter">handler</code> 作为 <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span>
  的有效性，而不是在调用时检测。
 </td>
</tr>

     <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">parser</code> 现在接受 <span class="classname"><a href="class.xmlparser.php" class="classname">XMLParser</a></span> 实例；之前接受有效的 <code class="literal">xml</code> <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>。
 </td>
</tr>

     <tr>
      <td>7.3.0</td>
      <td>
       如果扩展是针对 libxml 构建的，则不再忽略 <code class="parameter">handler</code> 的返回值。以前，会忽略返回值，且解析也从不停止。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


</div><?php manual_footer($setup); ?>