[PHP-DEV] Add a static initialization method to `BcMath\Number`

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):

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

On Sat, May 23, 2026, at 7:50 AM, Saki Takamachi wrote:

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):
BcMath\Number::createFrom · Issue #22128 · php/php-src · GitHub

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

On Saturday, 23 May 2026 at 14:53, Saki Takamachi <saki@sakiot.com> wrote:

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):
BcMath\Number::createFrom · Issue #22128 · php/php-src · GitHub

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] core: set zend_pass_function as default constructor by Girgias · Pull Request #19797 · php/php-src · GitHub