Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:122789
X-Original-To: internals@lists.php.net
Delivered-To: internals@lists.php.net
Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5])
	by qa.php.net (Postfix) with ESMTPS id 3D0171A009C
	for <internals@lists.php.net>; Thu, 28 Mar 2024 13:30:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
	t=1711632659; bh=1eg9itqgZaCKTiUpaLIfDDhBOK6GSE2Y31W3f2r73pI=;
	h=Subject:From:In-Reply-To:Date:Cc:References:To:From;
	b=MeoxN4wriqzQZo7xl1TmF/qQxaBfLwAyV/qXtrZWPyZolK6GCLiUqZqy/EjoCc702
	 JMCQ0SW4AmDkwYdEu95d3J2v8XaIMQMxShlRH3HKx1BzF3Xq6pcX2B1rbSFtdVkNPf
	 puoieAHK1wfNk9ulL8Jm8PCth9eGcROE37WXHESrr0jHchq2h+NzwpI2KVYD9EH8Yu
	 FBuANyejsDiRTnUZr8gL4sGf1DrL/wpi++vzIx6unc4K2s7vgmPmt44J96G166lWN7
	 5NaADthfRX/Y2WhLUXs7EsbMYb28KHVFGMH5WKSqOFApXANOQerTq9MSDOxqIz3T+K
	 wKZph4nvv6xIQ==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id CDA92180004
	for <internals@lists.php.net>; Thu, 28 Mar 2024 13:30:57 +0000 (UTC)
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net
X-Spam-Level: 
X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE,
	SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no
	version=4.0.0
X-Spam-Virus: No
X-Envelope-From: <saki@sakiot.com>
Received: from mail.sakiot.com (mail.sakiot.com [160.16.227.216])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by php-smtp4.php.net (Postfix) with ESMTPS
	for <internals@lists.php.net>; Thu, 28 Mar 2024 13:30:56 +0000 (UTC)
Received: from smtpclient.apple (unknown [117.55.37.250])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by mail.sakiot.com (Postfix) with ESMTPSA id CBC00401E7;
	Thu, 28 Mar 2024 22:30:28 +0900 (JST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com;
	s=default; t=1711632628;
	bh=1eg9itqgZaCKTiUpaLIfDDhBOK6GSE2Y31W3f2r73pI=;
	h=Subject:From:In-Reply-To:Date:Cc:References:To:From;
	b=EJ9qaZ8mBoI/5/1CV1oHC3jGvElYgsZoxNNbngVUdEp1rp6fvxnMEg/8DV7oRLuVN
	 mq2H+dlZMl6xt57SIorGjxPyhlm7aLXxjVeCokF5ZZrxFDloiLwS8e582xHSuXyBUd
	 bhpC1yNNcTgeG95qCLqZPGOqBbMgd1fDwIn/su20=
Content-Type: text/plain;
	charset=utf-8
Precedence: bulk
list-help: <mailto:internals+help@lists.php.net
list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net>
list-post: <mailto:internals@lists.php.net>
List-Id: internals.lists.php.net
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\))
Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath
In-Reply-To: <62e27e46-f911-5a71-6527-8bba21bf0964@php.net>
Date: Thu, 28 Mar 2024 22:30:15 +0900
Cc: php internals <internals@lists.php.net>
Content-Transfer-Encoding: quoted-printable
Message-ID: <48803EBD-33BB-4433-B125-448759A81868@sakiot.com>
References: <4F094EDA-5058-407D-AF39-06FD934FDE1F@sakiot.com>
 <bbcff629-4dd6-bc50-ac9f-641849dc218a@php.net>
 <68CF373E-6ABF-4471-8992-813B4BA1B508@sakiot.com>
 <62e27e46-f911-5a71-6527-8bba21bf0964@php.net>
To: Derick Rethans <derick@php.net>
X-Mailer: Apple Mail (2.3731.700.6)
From: saki@sakiot.com (Saki Takamachi)

Hi Derick,

>> What is the main difference between getting a read-only property with=20=

>> `->value` and getting the value using a method?
>=20
> Feeling :-) Do we have precedence with other extension's objects=20
> perhaps already?

It depends on the extension. Probably some readonly properties exist in =
mysqli for example. (However, those in mysqli are only readonly =
internally, and stubs are not readonly. Therefore, many IDEs do not =
display errors, so w e don't realize we've written incorrect code until =
runtime.)
The Readonly property was implemented since PHP 8.1, so inner classes =
implemented before then did not have the option of using the readonly =
property. As far as I know, no new inner classes with readonly =
properties or simple getters have been added since PHP 8.1. Therefore, =
there is currently no precedent that can be compared on the same terms =
as `BCMath\Number`=E2=80=A6.


>> `bcfloor` and `bcceil` originally have no scale specification. This =
is=20
>> because the result is always a string representing an integer value.=20=

>> And since the supported round-mode is the same as standard-round,=20
>> `ROUND_FLOOR` and `ROUND_CEILING` are also supported. Therefore, if=20=

>> want to obtain floor or ceil behavior with a specified scale, I=20
>> recommend specifying the mode as round.
>=20
> OK. That makes sense.

Note that we have removed $scale from the calculation method arguments, =
reflecting the discussion on the mailing list :)


>>> - In this example, what would $result->scale show? (Perhaps add that =
to=20
>>> the example?):
>>>=20
>>> <?php
>>> $num =3D new BcNum('1.23', 2);
>>> $result =3D $num + '1.23456';
>>> $result->value; // '2.46456'
>>> $result->scale; // ??
>>=20
>> In this case, `$result->scale` will be `'5'`. I added this to the =
RFC.
>=20
> Great.=20

This has also been changed to reflect discussion, with slightly =
different results.
```
$num =3D new BcNum('1.23', 2);
$result =3D $num + '1.23456';
$result->value; // '2.46'
$result->scale; // 2
```

> It's what we did for the Date extension, and the Random extension, but=20=

> in this case, it's probably not needed as you say.

> For that, yes. ValueErrors should be distinct from DivideByZeroError =
=E2=80=94 I=20
> think we do have both of those already:
>=20
> php -r 'echo 8/0;'
>=20
> Fatal error: Uncaught DivisionByZeroError: Division by zero in Command=20=

> line code on line 1
>=20
> =46rom the docs for ValueError:
>=20
> "A ValueError is thrown when the type of an argument is correct but =
the=20
> value of it is incorrect."
>=20
> =46rom the docs for DivisionByZeroError:
>=20
> " DivisionByZeroError is thrown when an attempt is made to divide a=20
> number by zero. "
>=20
> Subclassing these for BCMath objects seems unnecessary therefore.

Thanks. Sorry, I meant "If I create dedicated exception classes, do I =
need separate classes for each type of error?=E2=80=9D I couldn't write =
it well in English.

Regards.

Saki=