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

FIX: Boolean ’t’/‘f’ strings need to be coerced to int properly. #93

Merged
merged 1 commit into from
Jan 23, 2019
Merged

FIX: Boolean ’t’/‘f’ strings need to be coerced to int properly. #93

merged 1 commit into from
Jan 23, 2019

Conversation

sminnee
Copy link
Member

@sminnee sminnee commented Jan 23, 2019

Noticed this bug.

The database was returning booleans as the strings "t" or "f". The f is being coerced to 0, but so was t. This coerces t to 1.

if ($type === 'bool' && $record[$k] === 't') {
$record[$k] = 1;
} else {
settype($record[$k], self::$typeMapping[$type]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this implicitly handle f values?

Copy link
Member Author

@sminnee sminnee Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah $d = 'f'; settype($d, 'int'); return $d returns 0. Is it too hacky to rely on that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment? I was just curious

@sminnee
Copy link
Member Author

sminnee commented Jan 23, 2019

PS: If you're happy feel free to merge ;-)

@robbieaverill robbieaverill merged commit f85b46d into silverstripe:2 Jan 23, 2019
sminnee pushed a commit that referenced this pull request Jan 23, 2019
@sminnee
Copy link
Member Author

sminnee commented Jan 23, 2019

Cheeky direct-commit to the 2 branch: fd27c17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants