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

Fix for php 8.1.2 / Ubuntu 22.04 #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hjtappe
Copy link

@hjtappe hjtappe commented Jan 7, 2023

Make script usable in recent environment: Add robustness to remove PHP warnings and deprecated bahavior.

{
$temp = explode(';', $home[0][0]);
$vcard->home += array(
$vcard->home = array_merge($vcard->home, array(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The add operator + is not equal to array_merge(): "for keys that exist in both arrays, the elements from the left-hand array will be used" whereas with array_merge, the second argument wins.

What's the problem with the add operator in PHP 8 (haven't tested it)?

@thomascube
Copy link
Owner

Hello @hjtappe. Thanks a lot for your work! I somehow lost track with the updates of PHP and I'm happy for your contribution. The only thing I'm not sure is the replacement of the + array operator with array_merge() (see inline comment)

@hjtappe
Copy link
Author

hjtappe commented Feb 22, 2023

Hello @thomascube,

  1. Not initializing the four arrays led to many PHP warnings about undefined array members, so I initialized the arrays with the expected key-value pairs.
  2. Now, using the + operator on the pre-initialized array keeps the original (empty) values.
  3. I don't see that not overwriting an existing value would change the program behavior because it is an associative array, which can hold only one value per key anyways. That would be different on plain value-only arrays, which would grow in that case.

So, we could only revert back to the + operator if we check all use places of array keys with a defined() call, which I deem unnecessary for what the program does at these lines. Just replacing the array_merge with the plus operator will now lead to missing data in the export output.

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

2 participants