Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 305646

UserInterface::id(), AccountInterface::id() should return int to match typehints

$
0
0

Problem/Motivation

Dependent upon database abstraction layer connection configuration the database may return string like integers as strings or as integers. Both are usually later passed through the entity stack without modification.

AccountInterface::id()'s typehint states it returns an integer, but this is not true in many (all?) cases. Weakly typed as PHP is, uids stored on AccountProxy, UserSession, UserInterface may return the uid as a string. This prevents strongly typed comparison, e.g. $currentUser->id() === $ownerIdAsInteger, if one is represented as an integer and the other a string. Or, it will fail strict type enforcement if passed to a method which expects an integer.

Steps to reproduce

Proposed resolution

Classes implementing AccountInterface::id() should ensure they return an integer as documented by the the API.
(Affirmed by Framework Managers see #43 and #44.

Remaining tasks

Framework manager decision on if a class implementing AccountIinterface::id() should:

  1. Return integers as documented in the API (cast string's returned by the DB layer to int)
  2. Change the API Spec for AccountInterface::id() to return string

Note:
In both cases we appear to need to add |null as well.

User interface changes

None

API changes

Data model changes

None

Release notes snippet


Viewing all articles
Browse latest Browse all 305646

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>