Function strpos() has the arguments swapped

Created on 19 September 2024, 3 months ago

Problem/Motivation

`strpos()` has the arguments swapped, in the method `private_message_preprocess_container()`.

Wrong: `strpos('edit-members-wrapper', $vars['element']['#id'])`
Correct: `strpos($vars['element']['#id'], 'edit-members-wrapper')`

I recall, the first argument is the haystack and the second is the needle. See here.

This is usually unnoticed because the needle is exactly the same has the haystack. But in my case I'm using a modal and the id comes concatenated with a token. In this case, `strpos()` returns false when it should return true.

Steps to reproduce

Just looking at the code, you can see that the arguments are swapped. It doesn't make sense to check if `$vars['element']['#id']` is a substring `'edit-members-wrapper'`.

If you really want to see this break, you can make the link to Create Private Message (route `private_message.private_message_page`) to open in a modal. This requires some simple steps that I won't put here.

Proposed resolution

Use the function `str_starts_with()` with the correct arguments.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇵🇹Portugal dxvargas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024