Re: Anonymous classes share static space?

From: Date: Mon, 23 Oct 2017 19:23:49 +0000
Subject: Re: Anonymous classes share static space?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-326241@lists.php.net to get a copy of this message
Greetings, "Christoph M. Becker". In reply to Your message dated Sunday, October 22, 2017, 23:37:16, > On 22.10.2017 at 15:08, Andrey Repin wrote: >> https://3v4l.org/vLjTI >> >> <?php >> >> function creator($var) >> { >> return new class($var) { >> private static $var; >> function __construct($var) >> { >> static::$var = $var; >> } >> >> function __debugInfo() >> { >> return [ >> "\0*\0var" => static::$var, >> ]; >> } >> }; >> } >> >> $a = creator('A'); >> $b = creator('B'); >> var_dump($a, $b, $a === $b); >> >> >>> The output: >> >> object(class@anonymous)#1 (1) { >> ["var":protected]=> >> string(1) "B" >> } >> object(class@anonymous)#2 (1) { >> ["var":protected]=> >> string(1) "B" >> } >> bool(false) >> >> >> However, the output contradicting itself. >> By behavior, the two objects are of the same class, by comparison - they are not. >> Is this… intended behavior? > The === operator compares objects by identity. In this case the objects > have the same class, and are equal (==)[1], but not identical. > [1] <https://3v4l.org/NEBTd> Ok, then following your statement, this code: https://3v4l.org/Bgjqn should yield: D/D… Since objects are of the same class… -- Sincerely Yours, Andrey Repin <anrdaemon@freemail.ru>

« previous php.general (#326241) next »