Skip to content

DBAL36 - BIGINT documentation misunderstanding #6126

Closed
@cizordj

Description

@cizordj

Bug Report

Q A
Version 3.6.5

Summary

Please rephrase the explanation in the docs about the BIGINT datatype.

Current behaviour

The current statements lead to misinterpretation:

<!-- dbal/docs/en/reference/types.rst:90 -->
Values retrieved from the database are always converted to PHP's ``string`` type
or ``null`` if no data is present.
<!-- dbal/docs/en/reference/types.rst:95 -->
For compatibility reasons this type is not converted to an integer

Which is not true.

We have many entities mapped with BIGINT and BIGSERIAL in a PostgreSQL database
and doctrine always casts their value to a regular PHP integer. We use the 64 bit architecture
and the primary keys are mapped this way.

<?php
class User {
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'SEQUENCE')]
    #[ORM\SequenceGenerator(
        sequenceName: 'user.user_id_user_seq',
        allocationSize: 1,
        initialValue: 1
    )]
    #[ORM\Column(name: 'id_user', type: Types::BIGINT)]
    private ?int $id = null;
}

According to the PostgreSQL's documentation the maximum number for a BIGINT field is 9223372036854775807 which is the same as the PHP_INT_MAX.

How to reproduce

  • Make an entity whose primary key represents a BIGINT type in the database.
  • Run the respective migration
  • Add a row to the table via a SQL script
  • Fetch that entity using that entity's repository via Symfony Commands or Regular Controllers
  • Debug the datatype via dd() or let it serialize it through a JsonResponse.

You'll notice that the value comes as a PHP integer.

You can also add another row to the table with the maximum possible value, see the value of PHP_INT_MAX and make an insertion to the database.
Fetch all the entities and you can see that the value still comes as a regular integer type.

Due to the limitations of JSON, things start to get really weird for numbers like this, so you can only trust the dd() output in this case.

Expected behaviour

The docs should say that the values retrieved from the database are always converted to PHP's int type or null if no data is present and display a notice about it being cast to string only in legacy 32-bit platforms.

Btw why have you guys changed your minds? #2976

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