Re: readonly properties

From: Date: Wed, 18 Aug 2021 12:28:35 +0000
Subject: Re: readonly properties
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-115762@lists.php.net to get a copy of this message
> > >> 2. DateInterval->days > >> > >> $interval = (new DateTime())->diff(new DateTime()); > >> var_dump($interval->days); // 0 > >> $refl = (new ReflectionObject($interval))->getProperty('days'); > >> var_dump($refl->isReadOnly()); // false > >> var_dump($refl->isPublic()); // true > >> $interval->days = 2; > >> var_dump($interval->days); // 0 > >> > > The DateInterval properties are currently implemented as getters/setters > on > > some internal state. Some of those are getter-only, but probably not > fully > > immutable. > > I was referring to the property "days" only as this is a non writable > value generated on "DateTime->diff". > > As you can see in the snipped it doesn't allow to modify days but it > also doesn't fail which seems wrong to me. > > I don't have much knowledge about internals but would it be possible to > define "public readonly int|false $days" not using getters/setters and > keep all other properties as it? > Hi, FWIW, I too agree that [$interval->days, $interval->days = 2, $interval->days] giving [0, 2, 0] without any warning (or https://3v4l.org/h8Cju for a variation) seems wrong. Regards, -- Guilliam Xavier

« previous php.internals (#115762) next »