On Tue, 17 Jan 2023, Christian Schneider wrote:
> Am 17.01.2023 um 15:59 schrieb G. P. B. <[email protected]>:
> >
> > I might be again misunderstanding, but one cannot extend an enum as
> > they are final classes under the hood. Currently, the only other
> > native enum is the one that was added with the Randomizer Additions
> > RFC [1] so this topic hasn't come up yet as the enum for ext-random
> > is definetely complete.
>
> I'm talking about adding new values in later PHP versions, let's for
> example assume they would add a SameSite mode "Stricter" and PHP wants
> to support that. How would one write code to use "Stricter" in code
> meant to work for both old and new PHP versions?
if (version_compare(phpversion(), "8.4.0", ">")) {
setcookie("test", "value", samesite: SameSite::Stricter);
} else {
setcookie("test", "value", samesite: SameSite::Strict);
}
These are run time checks, not compile time:
8 > JMPZ $1, ->18
...
13 FETCH_CLASS_CONSTANT ~2
'SameSite', 'Stricter'
...
17 > JMP ->26
18 > EXT_STMT
...
22 FETCH_CLASS_CONSTANT ~4
'SameSite', 'Strict'
cheers,
Derick
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php