Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError | Library/Configuration.php::getLdapAttributes, line 378: str_ends_with(): Argument #1 ($haystack) must be of type string, int given #242

Open
cgrisu opened this issue Dec 17, 2024 · 2 comments

Comments

@cgrisu
Copy link

cgrisu commented Dec 17, 2024

Hey,

I just got this exception after an update from 3.7 to 4.0.2, and PHP from 7.4 to 8.2.

The method parameter is an associative array for simple field mappings: ['title' => '<dn>'].
With my hook mapping department = {hookName|department} the param is a flat array: ['{hookName|department}']

This check fails, since $field is an index:

foreach ($mapping as $field => $attribute) {
    if (str_ends_with($field, '.')) {
    ...

I checked the docs reagrding hooks, but looks like nothing has changed.

A quick fix in my case was changing this call

$ldapAttributes = Configuration::getLdapAttributes([$value]);

to $ldapAttributes = Configuration::getLdapAttributes([$field => $value]);

We have quite a simple setup, I didn't really test much further, but seems to work in my case.

@Nimmermaer
Copy link

Same here.
My quick fix was cast the $field variable to a string to ensure compatibility with str_ends_with.
This avoids potential type errors and allows the condition to work as intended.

if (str_ends_with((string)$field, '.')) { // This is a TypoScript configuration continue; }

@xperseguers
Copy link
Owner

Casting to string sounds good. mind opening a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants