-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Stop binding numerically formatted strings as TYPE_NUMERIC #753
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
Conversation
Now, string values are always treated as TYPE_STRING. To store a numeric value using the type auto-detection logic, one should a numeric type. There are many use cases where strings that look like numbers should be treated as strings: telephone numbers, employee ID numbers, purchase order numbers, etc. Fixes #752
@@ -58,15 +58,6 @@ public static function dataTypeForValue($pValue) | |||
} elseif (is_bool($pValue)) { | |||
return DataType::TYPE_BOOL; | |||
} elseif (is_float($pValue) || is_int($pValue)) { | |||
return DataType::TYPE_NUMERIC; | |||
} elseif (preg_match('/^[\+\-]?(\d+\\.?\d*|\d*\\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) { |
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.
Maybe instead of removing it, this should be moved to AdvancedValueBinder
.
I really am not comfortable with this change of behaviour.... we created the concept of binders to allow advanced users to control datatyping, while providing the default as something that simplified datatype handling for less advance users.... and I spend more than enough time explaining to people that |
The logic being removed here assesses the value of strings containing numeric values to see if they begin with a leading zero; and if so, treats them as strings.... the "non-greedy" evaluation of numeric values is supposed to handle telephone numbers, social security numbers, etc such as '0123456' as strings rather than setting them as a numeric type. |
That is not what I'm suggesting. I'm suggesting that string types be treated as strings. Integers, floating point numbers, date objects, etc. should still be stored in the document as the more obvious type. |
OK, my bad.... but that does not change my opinion on this issue. That vast majority of PHP developers using this library do not fully understand datatyping and the differences between |
Mark opinion seems to join my own. @jdufresne if you are willing to modify this PR, or create a new one, to have a new If you'd rather not invest more time in this, then we'll close as WONTFIX, because Mark and myself probably won't have much time to implement it ourselves. |
Thanks for taking the time to respond. I won't have the time to continue working on this so I'll close this PR for now. Cheers. |
Now, string values are always treated as TYPE_STRING. To store a numeric value using the type auto-detection logic, one should a numeric type.
Fixes #752
This is a new feature
Checklist:
Why this change is needed?
See issue #752