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

Remove error suppression to avoid undefined errors on PHP 8.1 #11

Merged
merged 4 commits into from
Jun 4, 2024

Conversation

gersonfs
Copy link
Contributor

@gersonfs gersonfs commented Oct 7, 2022

In php 8.1 we are getting an undefined index warning

@gersonfs
Copy link
Contributor Author

gersonfs commented Jun 3, 2024

ping @finwe

@finwe
Copy link
Member

finwe commented Jun 3, 2024

Include a unit test with a HTML/PHP code example this fixes. @gersonfs

Copy link
Member

@finwe finwe left a comment

Choose a reason for hiding this comment

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

I aggree that removing the silencing operator is somewhat cleaner eventhough this could be improved further:

  • We do not know what even is causing the missing key
  • Is the QR code complete when the issue is present?
  • Based on research above, could the suppressed "error" be reported instead of silenced? By throwing an exception on invalid data or at least logging?

src/QrCode.php Outdated
if ($remainingBit > $bufferBit) {
$this->wordData[$wordCount] = ((@$this->wordData[$wordCount] << $bufferBit) | $bufferVal);
$this->wordData[$wordCount] = (($wordDataValue << $bufferBit) | $bufferVal);
Copy link
Member

Choose a reason for hiding this comment

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

why bitshift the value anyway when we know it is null? Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I don't work with operators like this, I thought you would know better. Why does the algorithm try to access a non-existent index?

src/QrCode.php Outdated
$remainingBit -= $bufferBit;
$flag = false;
} else {
$bufferBit -= $remainingBit;
$this->wordData[$wordCount] = ((@$this->wordData[$wordCount] << $remainingBit) | ($bufferVal >> $bufferBit));
$this->wordData[$wordCount] = (($wordDataValue << $remainingBit) | ($bufferVal >> $bufferBit));
Copy link
Member

Choose a reason for hiding this comment

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

See above.

@finwe
Copy link
Member

finwe commented Jun 3, 2024

Oh, and the test code example from the other PR would be completely OK to add here.

@gersonfs
Copy link
Contributor Author

gersonfs commented Jun 3, 2024

Is the QR code complete when the issue is present?
From my tests, yes, I am even using it in production. Note that the behavior of the algorithm remains the same.

Based on research above, could the suppressed "error" be reported instead of silenced? By throwing an exception on invalid data or at least logging?
I didn't try to change the behavior of the algorithm, I honestly didn't understand its logic.
If the automated tests passed, I imagine it did not cause any type of damage. Or the tests are liars.

I aggree that removing the silencing operator is somewhat cleaner eventhough this could be improved further:

  • We do not know what even is causing the missing key
  • Is the QR code complete when the issue is present?
  • Based on research above, could the suppressed "error" be reported instead of silenced? By throwing an exception on invalid data or at least logging?

@finwe
Copy link
Member

finwe commented Jun 4, 2024

Well, after debugging the loop a bit it seems the cleanest way would be to initialize the array key directly with 0 directly after the while ($flag) { check.

$this->wordData[$wordCount] = isset($this->wordData[$wordCount]) ? $this->wordData[$wordCount] : 0;

@gersonfs
Copy link
Contributor Author

gersonfs commented Jun 4, 2024

@finwe do you thing is ok now?

@finwe finwe merged commit c38b7fb into mpdf:development Jun 4, 2024
17 checks passed
@finwe
Copy link
Member

finwe commented Jun 4, 2024

Seems OK, thanks!

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.

2 participants