<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/reserved.attributes.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'class.override.php',
    1 => 'Override',
    2 => 'The Override attribute',
  ),
  'up' => 
  array (
    0 => 'reserved.attributes.php',
    1 => 'Predefined Attributes',
  ),
  'prev' => 
  array (
    0 => 'nodiscard.construct.php',
    1 => 'NoDiscard::__construct',
  ),
  'next' => 
  array (
    0 => 'override.construct.php',
    1 => 'Override::__construct',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/predefined/attributes/override.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.override.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.override" class="reference">
 <h1 class="title">The Override attribute</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 8 &gt;= 8.3.0)</p>

  <div class="section" id="override.intro">
   <h2 class="title">Introduzione</h2>
   <p class="simpara">
    This attribute is used to indicate that a method or a property is intended
    to override a method or a property of a parent class or that it implements
    a method or a property defined in an interface.
   </p>
   <p class="simpara">
    If no method or property with the same name exists in a parent class or
    in an implemented interface a compile-time error will be
    emitted.
   </p>
   <p class="simpara">
    The attribute cannot be used on the
    <a href="language.oop5.decon.php#object.construct" class="link">__construct()</a>
    method, which is exempt from signature checks.
   </p>
  </div>

  <div class="section" id="override.synopsis">
   <h2 class="title">Sommario della classe</h2>

   <div class="classsynopsis"><div class="classsynopsisinfo">
    
     <span class="attribute"><a href="class.attribute.php">#[\Attribute]</a> </span><br>
     <span class="modifier">final</span>
     <span class="modifier">class</span> <strong class="classname"><strong class="classname">Override</strong></strong>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Metodi */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="override.construct.php" class="methodname">__construct</a></span>()</div>

   }</div>

  </div>

  <div class="section">
   <h2 class="title">Log delle modifiche</h2>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versione</th>
       <th>Descrizione</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.5.0</td>
       <td>
        <span class="classname"><strong class="classname">Override</strong></span> can be applied to properties.
       </td>
      </tr>

     </tbody>
    
   </table>

  </div>

  <div class="section">
   <h2 class="title">Esempi</h2>
   <div class="example" id="example-1">
    <p><strong>Example #1 Usage with methods</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Base </span><span style="color: #007700">{<br />    protected function </span><span style="color: #0000BB">foo</span><span style="color: #007700">(): </span><span style="color: #0000BB">void </span><span style="color: #007700">{}<br />}<br /><br />final class </span><span style="color: #0000BB">Extended </span><span style="color: #007700">extends </span><span style="color: #0000BB">Base </span><span style="color: #007700">{<br />    #[</span><span style="color: #0000BB">\Override</span><span style="color: #007700">]<br />    protected function </span><span style="color: #0000BB">boo</span><span style="color: #007700">(): </span><span style="color: #0000BB">void </span><span style="color: #007700">{}<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Output of the above example in PHP 8.3 is similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Fatal error: Extended::boo() has #[\Override] attribute, but no matching parent method exists
</pre></div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 Usage with properties</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Base </span><span style="color: #007700">{<br />    protected </span><span style="color: #0000BB">string $foo</span><span style="color: #007700">;<br />}<br /><br />final class </span><span style="color: #0000BB">Extended </span><span style="color: #007700">extends </span><span style="color: #0000BB">Base </span><span style="color: #007700">{<br />    #[</span><span style="color: #0000BB">\Override</span><span style="color: #007700">]<br />    protected </span><span style="color: #0000BB">string $boo</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Output of the above example in PHP 8.5 is similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Fatal error: Extended::$boo has #[\Override] attribute, but no matching parent property exists
</pre></div>
    </div>
   </div>
  </div>

  <div class="section" id="override.seealso">
   <h2 class="title">Vedere anche:</h2>
   <ul class="simplelist">
    <li><a href="language.attributes.php" class="link">Attributes overview</a></li>
   </ul>
  </div>

 </div>

 





<h2>Indice dei contenuti</h2><ul class="chunklist chunklist_reference"><li><a href="override.construct.php">Override::__construct</a> — Construct a new Override attribute instance</li></ul>
</div>
<?php manual_footer($setup); ?>