Re: [RFC] [Discussion] Support object type in BCMath

From: Date: Tue, 26 Mar 2024 11:35:19 +0000
Subject: Re: [RFC] [Discussion] Support object type in BCMath
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-122746@lists.php.net to get a copy of this message
Hi Barney, thanks for the points and suggestions! > Is there any reason not to give the BcNum class a public readonly string > value property? Would just save a few characters of typing to use > value instead of getValue(). > Also as with the value, any reason not to make the scale a pubic readonly property? I had completely forgotten about the existence of read-only properties. That makes sense. > I suggest renaming setScale to > withScale. Although the docs will make clear that the object is > immutable, set is associated with mutation and might be confusing. > with is not as well known as a prefix but is associated with > immutable objects. Indeed, I felt uncomfortable using "set”. I didn't know that "with" was related to immutable. **I immediately reflected the above two points in my RFC** :D > One more suggestion - might it be worth adding a format > function to the new BcNum class? This would be similar to the existing number_format function, but > would avoid the need to lose precision by converting to float first. I came up with the following code, is it close to what you intended? ``` $num = BcNum::fromNumberFormat(1.2345, 5); $num->value; // 1.23450 ``` Regards. Saki

« previous php.internals (#122746) next »