Add support for IFS() logical function#1442
Add support for IFS() logical function#1442MarkBaker merged 6 commits intoPHPOffice:masterfrom Takitaf:master
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?) |
MarkBaker
left a comment
There was a problem hiding this comment.
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.
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.
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.
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
* Add support for IFS() logical function * Use Exception as false value in IFS logical function, so it never collides with string in spreadsheet
This is:
Checklist:
Why this change is needed?
PHPSpreadsheet missing Excel IFS logical function support