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

Modifying convertEmptyStringToNull function to pass variables by reference #221

Open
wants to merge 1 commit into
base: 2.0.0-dev
Choose a base branch
from

Conversation

tups
Copy link

@tups tups commented Jan 9, 2024

Good morning,

I noticed that the convertEmptyStringToNull function in your code was not working as expected when handling variables like $lastName, $firstName, etc. The reason is that these variables are passed by value in an array to the function, so changes made in the function are not reflected in the original variables.
Issue :

The current function takes an array of values and tries to replace empty strings with null. However, since the variables are passed by value, the changes are not applied to the original variables outside the function.
Proposed solution :

Modify the function to accept a variable number of arguments per reference. So any changes made to these variables within the function will reflect on the variables themselves.

Here is the modified code:

protected function convertEmptyStringToNull(&...$values): void
{
    foreach ($values as &$value) {
        if ($value === '') {
            $value = null;
        }
    }
}

And its use:

$this->convertEmptyStringToNull($lastName, $firstName, $additional, $prefix, $suffix);

Benefits of this change:

  • Increased flexibility: The function can now directly manipulate passed variables, making it more flexible and powerful.
  • Intuitive behavior: This modification makes the behavior of the function more intuitive and consistent with user expectations.
  • Ease of use: Users no longer need to create an array to pass variables to the function.

I think this change could benefit the robustness and usefulness of your library. I look forward to your feedback and am open to any further discussion or changes if necessary.

Thank you for your time and consideration.

Sincerely,

…bles in an array are only passed by reference.
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

Successfully merging this pull request may close these issues.

None yet

1 participant