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

Inconsistent string handling between Sum::sumErroringStrings() and Sum::sumIgnoringStrings() #3652

Closed
3 of 11 tasks
betterphp opened this issue Jul 27, 2023 · 1 comment · Fixed by #3653
Closed
3 of 11 tasks

Comments

@betterphp
Copy link
Contributor

This is:

What is the expected behaviour?

Numeric string handling in Sum::sumErroringStrings() and Sum::sumIgnoringStrings() should be consistent.

What is the current behaviour?

sumErroringStrings casts all string params to integers whereas sumIgnoringStrings just sums them. The expected behaviour would be for both functions to cast string inputs to floats.

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Sum;

// This outputs int(4)
var_dump(Sum::sumErroringStrings("1.2", "3.4"));

// This outputs float(4.6)
var_dump(Sum::sumIgnoringStrings("1.2", "3.4"));

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Yes, affects all formats

Which versions of PhpSpreadsheet and PHP are affected?

All PHP versions and 1.28 of phpspreadsheet

@betterphp betterphp changed the title Inconsistent string handling between Sum::sumErroringStrings() anbd Inconsistent string handling between Sum::sumErroringStrings() and Sum::sumIgnoringStrings() Jul 27, 2023
@betterphp
Copy link
Contributor Author

Created a PR for this #3653

oleibman added a commit that referenced this issue Aug 15, 2023
 (#3653)

* Fixed inconsistent string handling in SUM() implementations

* Use assertEqual instead of assertSame to allow ints and floats with the
same value

* Removewd special handling of empty strings and use default casts

* Eliminate Phpstan errors

* More Test Cases

* More New Tests

---------

Co-authored-by: oleibman <10341515+oleibman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant