Re: Anonymous classes share static space?

From: Date: Sun, 22 Oct 2017 13:42:21 +0000
Subject: Re: Anonymous classes share static space?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-326239@lists.php.net to get a copy of this message
On Sun, Oct 22, 2017 at 9:08 AM, Andrey Repin <anrdaemon@freemail.ru> wrote: > Greetings, All. > > 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? > > > -- > Sincerely Yours, Andrey Repin <anrdaemon@freemail.ru> > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > They are not the same class, they are anonymous.

« previous php.general (#326239) next »