# Add a static initialization method to `BcMath\Number`

- Thread: https://externals.io/message/130989
- Original archive: https://news-web.php.net/php.internals/130989
- Started by Saki Takamachi on 2026-05-23T12:50:15+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #130989 — Saki Takamachi — 2026-05-23T12:50:15+00:00

URL: https://externals.io/message/130989#130989

Hi internals!

In this issue, a suggestion was made that it would be convenient if `BcMath\Number` could be initialized in a callable-style form (i.e. initialized via a static method):
https://github.com/php/php-src/issues/22128

Indeed, as pointed out in the issue, similar static methods exist in classes such as `DateTime`.

I am in favor of introducing such a static method. It would probably look something like this:

```
// $scale is optional
$num = BcMath\Number::createFrom($val, $scale);
```

It would effectively serve as an alias for the constructor.

Incidentally, since this does not introduce any BC break, I do not believe an RFC is necessary.

I would like to hear everyone’s thoughts on this.

Regards,

Saki

---

## #130997 — Larry Garfield — 2026-05-23T18:58:05+00:00

URL: https://externals.io/message/130989#130997 · In reply to: #130989

> Hi internals!
>
> In this issue, a suggestion was made that it would be convenient if 
> `BcMath\Number` could be initialized in a callable-style form (i.e. 
> initialized via a static method):
> https://github.com/php/php-src/issues/22128
>
> Indeed, as pointed out in the issue, similar static methods exist in 
> classes such as `DateTime`.
>
> I am in favor of introducing such a static method. It would probably 
> look something like this:
>
> ```
> // $scale is optional
> $num = BcMath\Number::createFrom($val, $scale);
> ```
>
> It would effectively serve as an alias for the constructor.
>
> Incidentally, since this does not introduce any BC break, I do not 
> believe an RFC is necessary.
>
> I would like to hear everyone’s thoughts on this.
>
> Regards,
>
> Saki

I'm generally a fan of static factory methods like this, so +1 from me.  It would also allow it to be partialed by the new PFA syntax, too.

--Larry Garfield

---

## #131008 — Gina P. Banyard — 2026-05-25T09:07:20+00:00

URL: https://externals.io/message/130989#131008 · In reply to: #130989

> Hi internals!
> 
> In this issue, a suggestion was made that it would be convenient if `BcMath\Number` could be initialized in a callable-style form (i.e. initialized via a static method):
> https://github.com/php/php-src/issues/22128
> 
> Indeed, as pointed out in the issue, similar static methods exist in classes such as `DateTime`.
> 
> I am in favor of introducing such a static method. It would probably look something like this:
> 
> ```
> // $scale is optional
> $num = BcMath\Number::createFrom($val, $scale);
> ```
> 
> It would effectively serve as an alias for the constructor.
> 
> Incidentally, since this does not introduce any BC break, I do not believe an RFC is necessary.
> 
> I would like to hear everyone’s thoughts on this.

I'm against this.

We should instead find a solution to allow FCCs/PFAs to work on constructors and new rather than adding static factories for every possible class in existence.

I restarted work on a PR to clean up the semantics of constructors that, I believe, would make it feasible to allow FCCs/PFAs on new MyClass. [1]

Best regards,

Gina P. Banyard

[1] https://github.com/php/php-src/pull/19797

---

## #131047 — tim@bastelstu.be — 2026-05-29T08:29:49+00:00

URL: https://externals.io/message/130989#131047 · In reply to: #131008

Hi

Am 2026-05-25 11:07, schrieb Gina P. Banyard:
> I'm against this.
> 
> We should instead find a solution to allow FCCs/PFAs to work on 
> constructors and new rather than adding static factories for every 
> possible class in existence.

I agree with that and had also commented as such on the PR before seeing 
this thread.

Best regards
Tim Düsterhus

---

## #131048 — Marco Pivetta — 2026-05-29T08:42:33+00:00

URL: https://externals.io/message/130989#131048 · In reply to: #130989

Hey Saki,



> I am in favor of introducing such a static method. It would probably look
> something like this:
>
> ```
> // $scale is optional
> $num = BcMath\Number::createFrom($val, $scale);
> ```


I'm overall very much in favor of static factory methods: they are a clear
and established way of doing this in the ecosystem at large, with no
particular drawbacks, and better future BC boundaries.

Important though: `::createFrom()` is probably a bad name, and
`::fromValueAndScale()` or such would allow clearer/future expansion via
other constructors.

Marco Pivetta

https://mastodon.social/@ocramius

https://ocramius.github.io/

---

## #131059 — Larry Garfield — 2026-05-29T15:59:26+00:00

URL: https://externals.io/message/130989#131059 · In reply to: #131008

> We should instead find a solution to allow FCCs/PFAs to work on 
> constructors and new rather than adding static factories for every 
> possible class in existence.
>
> I restarted work on a PR to clean up the semantics of constructors 
> that, I believe, would make it feasible to allow FCCs/PFAs on new 
> MyClass. [1]

The original PFA RFC included constructor support, but it was complicated.  It was dropped from the new one that passed in order to simplify things, but I am open to re-adding it if a good approach is found.  So it should certainly be possible, just a bit hard.

--Larry Garfield

---

## #131209 — B.J. Scharp — 2026-06-12T07:19:22+00:00

URL: https://externals.io/message/130989#131209 · In reply to: #131059

> 
> 
> > […]
> 
> The original PFA RFC included constructor support, but it was complicated.  It was dropped from the new one that passed in order to simplify things, but I am open to re-adding it if a good approach is found.  So it should certainly be possible, just a bit hard.
> 
> --Larry Garfield


An idea that has always played through my head for this, was to add a 
syntax-alternative to "new MyClass()" in the form: 
"MyClass::__construct()". (In other words, make the constructor 
statically callable).

But seeing it was dropped from the initial RFC, it's probably not be as 
trivial as it seems.

It could even be argued that the constructor should have been a static 
method in the first place.

I only found out today that you can call "->__construct()" on an 
existing object. I don't really see a use case for that, to be honest, 
and with readonly properties and property-promotion it's a whole 
snake-pit all by itself.


Regards,
Bernard
