AccountInterface::getLastAccessedTime() implementors return incorrect data type

Created on 20 March 2018, over 6 years ago
Updated 21 August 2023, over 1 year ago

Problem/Motivation

According to documentation, User::getLastAccessedTime returns 0 if the user has never accessed the site:

A value of 0 means the user has never accessed the site

But in fact, the returned value in such case is '0' (string). And for users that accessed the site, the returned timestamp is also a string, when the expected returned value type is integer:

Return value
int Timestamp of the last access.

This is not accurate and makes it fail in some scenarios, like strict comparisons.

Proposed resolution

Basically, there would be two options:

  1. Cast the returned type to integer
  2. Change the documentation to reflect the real behaviour

I think the first option is the preferred one, since timestamps are numbers by definition, existing code using this method treats the returned value as a number and documentation update looks like an API change.

Remaining tasks

Cast the returned value as integer, review and test.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
User system 

Last updated 1 day ago

Created by

🇪🇸Spain manuel.adan 🌌

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024