-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add support for IFS() logical function #1442
Conversation
Thank you for this submission; I'l take a look at it this weekend, as it would be good to support the IFS() function |
@MarkBaker Thanks for a response. There is one detail in my implementation that probably needs to be changed. In theory I want to use existing functions if I can and also want to stop executing on a first condition that returned true. It works that way, but I use here the Additionally, there is a small chance, that user's "true value" would be exactly the same as I could calculate IFS in reverse order - calculate last condition, get previous condition and use last condition value as "false value" of previous condition, and repeat that until I reach the very first condition. It, however, makes this feature calculate always all conditions in each IFS statement. Maybe good enough solution is just introduce dummy value locally, that is even harder to collide with in real world (php_spreadsheet prefix + hash?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry that it's taken me so long to do a review of your submission; it really is useful to have an implementaton of IFS(); and I can understand your thinking about evaluation in reverse order, but that makes evaluation potentially slower if there are a lot of conditions
$returnIfTrue = ($arguments[$i + 1] === null) ? '' : Functions::flattenSingleValue($arguments[$i + 1]); | ||
$result = self::statementIf($testValue, $returnIfTrue, Functions::DUMMY()); | ||
|
||
if ($result !== Functions::DUMMY()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand your concern that there is a possibility that the returned result may be a valid case of the string '#Not Yet Implemented'
; unlikely, but not impossible.
I might be inclined to create something purely PHP detectable, that cannot exist in a spreadsheet, such as an exception. Maybe create a new EvaluateIfFalseException which can be returned as $result
rather than thrown; and directly type tested rather than simply value tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. Can I use just simple instance of generic Exception in that case: $falseValueException = new Exception();
? Not sure if we need special Exception for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you could use a standard Exception, I was simply thinking about readabilityand providing a named exception where the name provided contextual meaning
…lides with string in spreadsheet
… function. This prevents possible string collision with false value in spreadsheet
This is:
Checklist:
Why this change is needed?
PHPSpreadsheet missing Excel IFS logical function support