Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] (De)Normalizer for BcMath\Number class #59651

Copy link
Copy link
Closed
@faizanakram99

Description

@faizanakram99
Issue body actions

Description

PHP 8.4 got new Number class (from bcmath extension), it takes a $num parameter and as such simple numbers or numeric-strings cannot be deserialized (or denormalized) into Number class.

I am proposing to add a BcMathNumberNormalizer class similar to DateTimeNormalizer which would normalize Number class into int or numeric-string (if it is a decimal) and denormalize numeric-strings, floats and ints into BcMath\Number class.

Example

class Data
{
    public function __construct(
        public string $name,
        public Number $salary,
    ) {}
}

$data = [
    'name' => 'John Doe',
    'salary' => 1000,
];

$denormalized = $normalizer->denormalize($data, Data::class);

dump($denormalized);

outputs

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.