Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.php > #4760

Re: ::class und constant()

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From k@rl.pflaesterer.de (Karl Pflästerer)
Newsgroups de.comp.lang.php
Subject Re: ::class und constant()
Date Mon, 10 Jan 2022 22:29:01 +0100
Lines 33
Message-ID <m1v8yri8ki.fsf@mbp.pflaesterer.de> (permalink)
References <1t61dbfeaei1306d1n3e8%sfroehli@Froehlich.Priv.at>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace individual.net j1DYhLD6+Ekpge5oaF/nDw83hv7/pQZAq8E5ndVeTMEoeNz2k=
Cancel-Lock sha1:LgLBWHXekCsJmTyqGTKNnJyG/Ug= sha1:er/YAj4PFGe+a7yubcPccayzkVI=
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/26.3 (darwin)
Xref csiph.com de.comp.lang.php:4760

Show key headers only | View raw


Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) writes:

> Das folgende Codefragment:
>
> #v+
> <?php
>
> class C {
>         const c = 'c';
> }
>
> var_dump(constant('C::class'));
>
> ?>
> #v-
>
> ergibt bis einschließlich PHP 7.4 "NULL", ab PHP 8.0 offenbar (das
> habe ich nur mit 3v4l.org getestet) einen fatal error.
>
> Ist das ein Bug, ein Feature, oder halt einfach so passiert? Wieso
> darf ::class, das im Manual als "special constant" bezeichnet wird,
> nicht wie eine Konstante verwendet werden?

Was hättest du denn erwartet?

,----[ https://www.php.net/constant: ]
| 8.0.0 	If the constant is not defined, constant() now throws an Error
| exception; previously an E_WARNING was generated, and null was returned.
`----

Vorher ging es nicht und lieferte NULL, nun mit PHP 8 geht es nicht und
gibt eine Exception

Back to de.comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

::class und constant() Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2022-01-10 09:46 +0000
  Re: ::class und constant() k@rl.pflaesterer.de (Karl Pflästerer) - 2022-01-10 22:29 +0100
    Re: ::class und constant() Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2022-01-10 23:12 +0000
  Re: ::class und constant() Arno Welzel <usenet@arnowelzel.de> - 2022-01-11 11:50 +0100
    Re: ::class und constant() Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2022-01-11 13:41 +0000
      Re: ::class und constant() k@rl.pflaesterer.de (Karl Pflästerer) - 2022-01-11 16:40 +0100
        Re: ::class und constant() Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2022-01-11 17:36 +0000

csiph-web