codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
353 stars 130 forks source link

Bug: `defined()` used for function #1173

Closed FrancoisChaumont closed 3 weeks ago

FrancoisChaumont commented 3 weeks ago

PHP Version

8.3

CodeIgniter4 Version

4.5.4

Shield Version

dev-develop 223fbd9

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

MySQL 8.0.39

Did you customize Shield?

No

What happened?

In an attempt to create an email_helper and override the emailer function the system produces an error trying to redefine that function because the verification of a previously defined function of identical name is done using defined instead of function_exists.

Steps to Reproduce

Copy codeigniter4/shield/src/email_helper.php into app/Helpers

Expected Output

No error when overriding the emailer function

Anything else?

No response

datamweb commented 3 weeks ago

@FrancoisChaumont , Thank you for bringing this issue to our attention!

If you’re able to, we would encourage you to submit a Pull Request (PR) to address this issue. It would be great if you could refactor the code to use function_exists() instead of defined(), which will help prevent errors related to function redefinitions. Also, please make sure your GPG key is configured on your GitHub account before submitting the PR, as it is required for signature verification.

Additionally, could you please provide more details on why you need to override the helper function?

FrancoisChaumont commented 3 weeks ago

Hey @datamweb, Thanks for taking the time to get back to me about this.

Sure thing, I'll submit a PR in a little bit.

Overriding the helper was considered as an intent to white-label an existing solution (especially config values) but it turns out (after some head banging against the wall) that it's even necessary.