Skip to content

Unsupported operand types: int + string #526

Description

@nadar

From time to time sentry logs this error: Unsupported operand types: int + string

Stacktrace:

$payload = $this->redis->hget("$this->channel.messages", $id);
list($ttr, $message) = explode(';', $payload, 2);
$this->redis->zadd("$this->channel.reserved", time() + $ttr, $id);

https://github.com/yiisoft/yii2-queue/blob/master/src/drivers/redis/Queue.php#L160

For whatever reason $ttr seems to be a string instead of an int. Should we maybe typecast $ttr or throw an exception?

Activity

  1. samdark commented on Apr 24, 2025

    @samdark
    Member

    Yes. Let's typecast it.

  2. samdark commented on Apr 24, 2025

    @samdark
    Member

    Would you please create a pull request? Thanks.

  3. rob006 commented on Apr 24, 2025

    @rob006

    PHP should not complain about numerical strings in this case. You will get such error when you try something like time() + "abcd". Typecast wil result 0 in this case, and it will only hide bug in other place, that resulted invalid ttr.

    What is the value of $ttr when you have such error?

  4. nadar commented on Jul 8, 2025

    @nadar
    ContributorAuthor

    @rob006 sadly i can not say what is the value, we see it from time to time in sentry and those values are not logged - but it seems to be an issue somehow and typecast won't hurt? so can i send a PR or not?

  5. nadar commented on Jul 8, 2025

    @nadar
    ContributorAuthor
    Image
  6. rob006 commented on Jul 8, 2025

    @rob006

    and typecast won't hurt?

    It may hurt, if value is not a number - then it will be silently casted to 0 and this is not something you want. Cast will only hide real error (invalid ttr) in that case.

  7. nadar commented on Jul 8, 2025

    @nadar
    ContributorAuthor

    can we throw a better exception then? if (!is_number($ttr)) { throw new ....

  8. samdark commented on Jul 8, 2025

    @samdark
    Member

    @nadar yes. Better exception is an excellent idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions