<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.define.php',
    1 => 'define',
    2 => 'Definiert eine benannte Konstante',
  ),
  'up' => 
  array (
    0 => 'ref.misc.php',
    1 => 'Sonstige Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.constant.php',
    1 => 'constant',
  ),
  'next' => 
  array (
    0 => 'function.defined.php',
    1 => 'defined',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    'path' => 'reference/misc/functions/define.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.define" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">define</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">define</span> &mdash; <span class="dc-title">Definiert eine benannte Konstante</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.define-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>define</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$constant_name</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$case_insensitive</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Definiert während der Laufzeit eine benannte Konstante.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.define-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">constant_name</code></dt>
     <dd>
      <p class="para">
       Der Name der Konstante.
      </p>
      <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
       <p class="para">
        Es ist möglich, Konstanten mit reservierten oder gar ungültigen Namen
        mittels <span class="function"><strong>define()</strong></span> zu definieren, deren Wert (nur)
        mittels <span class="function"><a href="function.constant.php" class="function">constant()</a></span> gelesen werden kann. Allerdings
        wird dies nicht empfohlen.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       Der Wert der Konstante.
      </p>
      <div class="warning"><strong class="warning">Warnung</strong>
       <p class="para">
        Obgleich es möglich ist, Konstanten vom Typ <span class="type"><a href="language.types.resource.php" class="link">Ressource</a></span> zu
        definieren, wird dies nicht empfohlen, da es ein unvorhersagbares
        Verhalten des Programms zur Folge haben kann.
       </p>
      </div>
     </dd>
    
    
     <dt><code class="parameter">case_insensitive</code></dt>
     <dd>
      <p class="para">
       Falls auf <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> gesetzt, wird bei der Konstante nicht zwischen Groß-
       und Kleinschreibung unterschieden. In der Voreinstellung wird
       dazwischen unterschieden, d. h. <code class="literal">KONSTANTE</code> und
       <code class="literal">Konstante</code> repräsentieren unterschiedliche Werte.
      </p>
      <div class="warning"><strong class="warning">Warnung</strong>
       <p class="simpara">
        Das Definieren von Konstanten, die nicht zwischen Groß- und
        Kleinschreibung unterscheiden, wird von PHP 7.3.0 an missbilligt.
        Seit PHP 8.0.0 ist nur <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> ein zulässiger Wert; die Übergabe von
        <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> erzeugt eine Warnung.
       </p>
      </div>
      <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
       <p class="para">
        Groß-/Kleinschreibungsunabhängige Konstanten werden kleingeschrieben
        gespeichert.
       </p>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.define-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt bei Erfolg <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> zurück. Bei einem Fehler wird <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> zurückgegeben.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.define-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Beschreibung</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.1.0</td>
       <td>
        <code class="parameter">value</code> kann nun ein Objekt sein.
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        Die Übergabe von <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> an <code class="parameter">case_insensitive</code>
        gibt nun einen Fehler der Stufe <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> aus;
        die Übergabe von <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> ist weiterhin erlaubt.
       </td>
      </tr>

      <tr>
       <td>7.3.0</td>
       <td>
        <code class="parameter">case_insensitive</code> ist missbilligt und wird in
        Version 8.0.0 entfernt.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.define-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 Konstanten definieren</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">"KONSTANTE"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Hallo Welt."</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">KONSTANTE</span><span style="color: #007700">; </span><span style="color: #FF8000">// gibt "Hallo Welt." aus<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">Konstante</span><span style="color: #007700">; </span><span style="color: #FF8000">// gibt "Konstante" aus und erzeugt eine Warnung<br /><br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">"BEGRUESSUNG"</span><span style="color: #007700">, </span><span style="color: #DD0000">"Hallo Du."</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">BEGRUESSUNG</span><span style="color: #007700">; </span><span style="color: #FF8000">// gibt "Hallo Du." aus<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">Begruessung</span><span style="color: #007700">; </span><span style="color: #FF8000">// gibt "Hallo Du." aus<br /><br />// Funktioniert ab PHP 7<br /></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'ANIMALS'</span><span style="color: #007700">, array(<br />    </span><span style="color: #DD0000">'Hund'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'Katze'</span><span style="color: #007700">,<br />    </span><span style="color: #DD0000">'Maus'<br /></span><span style="color: #007700">));<br />echo </span><span style="color: #0000BB">ANIMALS</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]; </span><span style="color: #FF8000">// gibt "Katze" aus<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Beispiel #2 Konstanten mit reservierten Namen</strong></p>
    <div class="example-contents"><p>
     Dieses Beispiel verdeutlich die <em>Möglichkeit</em>, eine
     Konstante mit dem selben Namen wie eine
     <a href="language.constants.magic.php" class="link">magische Konstante</a>
     zu definieren. Da das resultierende Verhalten offensichtlich verwirrend
     ist, ist es nicht empfehlenswert, dies in der Praxis zu tun.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">defined</span><span style="color: #007700">(</span><span style="color: #DD0000">'__LINE__'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'__LINE__'</span><span style="color: #007700">, </span><span style="color: #DD0000">'test'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">constant</span><span style="color: #007700">(</span><span style="color: #DD0000">'__LINE__'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">__LINE__</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">bool(false)
bool(true)
string(4) &quot;test&quot;
int(5)</pre>
</div>
   </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.define-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.defined.php" class="function" rel="rdfs-seeAlso">defined()</a> - Pr&uuml;ft, ob eine Konstante mit dem angegebenen Namen existiert</span></li>
    <li><span class="function"><a href="function.constant.php" class="function" rel="rdfs-seeAlso">constant()</a> - Liefert den Wert einer Konstante</span></li>
    <li>
     Das Kapitel über <a href="language.constants.php" class="link">Konstanten</a>
    </li>
   </ul>
  </p>
 </div>


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