[5.8] Set Numeric value as Model Attribute#29714
Conversation
| */ | ||
| public function setAttribute($key, $value) | ||
| { | ||
| $key = (string) $key; |
There was a problem hiding this comment.
The phpdoc says that the key is already a string, so any code not passing a string to this function needs to be fixed, instead, and then this line removed.
There was a problem hiding this comment.
Thanks. Agree with that. I guess I should just cast string at the __set method in Model class like the following, right?
public function __set($key, $value)
{
$this->setAttribute((string) $key, $value);
}
There was a problem hiding this comment.
Although, there are a lot of other setAttribute method calls. Do you think all of them should cast string on their keys too?
There was a problem hiding this comment.
@GrahamCampbell I've updated the PR by changing the implementation as Suggested in the Issue. As casting the $key to string in every setAttribute call doesn't seem like a good solution to me.
There was a problem hiding this comment.
Thanks. Agree with that. I guess I should just cast string at the __set method in Model class like the following, right?
Any dynamic call to that method will already provide a non-empty string as the key. No need to cast.
If someone tries to set a Numeric value as a Model attribute, it will fail because of
isDateAttributemethods loose comparison inin_arraysearching.The details described in reported issue.
Simply casting all attributes to
stringinsetAttributemethod will resolve the issue.This PR fixes issue #29702