<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.domnode.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'domnode.replacechild.php',
    1 => 'DOMNode::replaceChild',
    2 => 'Replaces a child',
  ),
  'up' => 
  array (
    0 => 'class.domnode.php',
    1 => 'DOMNode',
  ),
  'prev' => 
  array (
    0 => 'domnode.removechild.php',
    1 => 'DOMNode::removeChild',
  ),
  'next' => 
  array (
    0 => 'domnode.sleep.php',
    1 => 'DOMNode::__sleep',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dom/domnode/replacechild.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="domnode.replacechild" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMNode::replaceChild</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DOMNode::replaceChild</span> &mdash; <span class="dc-title">
   Replaces a child
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domnode.replacechild-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DOMNode::replaceChild</strong></span>(<span class="methodparam"><span class="type"><a href="class.domnode.php" class="type DOMNode">DOMNode</a></span> <code class="parameter">$node</code></span>, <span class="methodparam"><span class="type"><a href="class.domnode.php" class="type DOMNode">DOMNode</a></span> <code class="parameter">$child</code></span>): <span class="type"><span class="type"><a href="class.domnode.php" class="type DOMNode">DOMNode</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   This function replaces the child <code class="parameter">child</code> 
   with the passed new node. If the <code class="parameter">node</code> is already a child it 
   will not be added a second time. If the replacement succeeds the 
   old node is returned.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-domnode.replacechild-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">node</code></dt>
     <dd>
      <p class="para">
       The new node. It must be a member of the target document, i.e.
       created by one of the DOMDocument-&gt;createXXX() methods or imported in
       the document by <a href="domdocument.importnode.php" class="xref">DOMDocument::importNode</a>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">child</code></dt>
     <dd>
      <p class="para">
       The old node.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-domnode.replacechild-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   The old node or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if an error occur.
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-domnode.replacechild-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="simpara">
   May throw a <span class="exceptionname"><a href="class.domexception.php" class="exceptionname">DOMException</a></span> with the
   following error codes:
  </p>
  <p class="para">
   <dl>
    
     <dt><strong><code><a href="dom.constants.php#constant.dom-no-modification-allowed-err">DOM_NO_MODIFICATION_ALLOWED_ERR</a></code></strong></dt>
     <dd>
      <p class="para">
       Raised if this node is readonly or if the previous parent of the node
       being inserted is readonly.
      </p>
     </dd>
    
    
     <dt><strong><code><a href="dom.constants.php#constant.dom-hierarchy-request-err">DOM_HIERARCHY_REQUEST_ERR</a></code></strong></dt>
     <dd>
      <p class="para">
       Raised if this node is of a type that does not allow children of the 
       type of the <code class="parameter">node</code> node, or if the node to 
       put in is one of this node&#039;s ancestors or this node itself.
      </p>
     </dd>
    
    
     <dt><strong><code><a href="dom.constants.php#constant.dom-wrong-document-err">DOM_WRONG_DOCUMENT_ERR</a></code></strong></dt>
     <dd>
      <p class="para">
       Raised if <code class="parameter">node</code> was created from a different 
       document than the one that created this node.
      </p>
     </dd>
    
    
     <dt><strong><code><a href="dom.constants.php#constant.dom-not-found-err">DOM_NOT_FOUND_ERR</a></code></strong></dt>
     <dd>
      <p class="para">
       Raised if <code class="parameter">child</code> is not a child of this node.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-domnode.replacechild-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="domchildnode.replacewith.php" class="methodname" rel="rdfs-seeAlso">DOMChildNode::replaceWith()</a> - Replaces the node with new nodes</span></li>
    <li><span class="methodname"><a href="domnode.appendchild.php" class="methodname" rel="rdfs-seeAlso">DOMNode::appendChild()</a> - Adds new child at the end of the children</span></li>
    <li><span class="methodname"><a href="domnode.removechild.php" class="methodname" rel="rdfs-seeAlso">DOMNode::removeChild()</a> - Removes child from list of children</span></li>
   </ul>
  </p>
 </div>

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