Comments (9)
Well, the name ideally indicates what the functionality will be. We can have both (getBoolean
and getAsBoolean
) or just the latter with an optional param to be strict/er. I think we're on the same page, let's see what others think.
from silverstripe-framework.
Right, but equally you could try to set a value to true, miss a typo and it’ll silently fall back to false with no warning/error - that sounds worse to me. Environment variables tend to be critical to a site operating properly, I’d rather be notified if I’d set something incorrectly than it silently fall back to a value I may or may not have intended
from silverstripe-framework.
My 2 cents for the decisions/questions:
- if it's not set, it's not set and is empty, so return
null
- if it's set and not a boolean-like, then
getAsBoolean
should imho return false (we should NOT use theFILTER_NULL_ON_FAILURE
flag).
from silverstripe-framework.
- if it's not set, it's not set and is empty, so return
null
I tend to agree with that.
- if it's set and not a boolean-like, then
getAsBoolean
should imho return false (we should NOT use theFILTER_NULL_ON_FAILURE
flag).
What's your thinking there? To me that seems more like someone has set an incorrect value for that variable and we shouldn't try to guess at what their intention was. I lean towards throwing a RuntimeException
in that scenario. We could provide people with a valueIsBoolean()
method as well if we want to provide developers with a way to avoid exceptions and try/catching.
from silverstripe-framework.
- if it's set and not a boolean-like, then
getAsBoolean
should imho return false (we should NOT use theFILTER_NULL_ON_FAILURE
flag).What's your thinking there? To me that seems more like someone has set an incorrect value for that variable and we shouldn't try to guess at what their intention was. I lean towards throwing a
RuntimeException
in that scenario. We could provide people with avalueIsBoolean()
method as well if we want to provide developers with a way to avoid exceptions and try/catching.
Get 'whatever' as boolean. We shouldn't be guessing, as you say. If it was named getBoolean
then we can throw an exception if not boolean-like.
from silverstripe-framework.
So it's really a question of naming rather than functionality? I'd be happy with naming it getBoolean()
and use the safer behaviour.
from silverstripe-framework.
just the latter with an optional param to be strict/er
I like that idea
from silverstripe-framework.
I’d be in favour of implementing only getBoolean()
and throwing an exception on a non-boolean value. If you’re trying to get a boolean value from an environment variable and someone has set a non-boolean value, that’s an error that should be highlighted. I can’t really imagine a valid use case for the getAsBoolean()
soft-fail version
from silverstripe-framework.
@kinglozzer imagine just missing a typo in the secret value and having to do a full redeployment on SCP taking an hour while not being able to see what the value is.. I'd rather have a soft-fail since everything defaults to false if not truthy as seen by filter_var
which to me feels safer. But I'm probably not the target audience here.
from silverstripe-framework.
Related Issues (20)
- MoneyField: Move field generation from constructor to custom method HOT 1
- mariadb builds broken HOT 2
- encryptWithUserSettings assumes there is a salt HOT 1
- Form scaffolder should keep original field order HOT 2
- NumericField doesn't valid properly numbers > 1000 with locale fr-Fr HOT 3
- type mismatch HOT 1
- Orphan polymorphic relations get assigned to random DataObject class HOT 3
- Run CanonicalURLMiddleware in dev / test. HOT 2
- Add Nice() to DBField HOT 10
- BUG Eager loading with multiple objects pointing to the same has_one trigger extra db fetch HOT 1
- TimeField should deal better with partial times HOT 1
- Improve phpdoc types HOT 3
- GridField breadcrumbs may use incorrect casting for titles
- Revert TinyMCE config bugfix prior to CMS 5.2 release HOT 2
- ClassInfo::hasTable could be cached on dev/build HOT 3
- ImageBackend 'auto' driver HOT 5
- Invalid french translation in ChangePasswordEmail HOT 1
- Duplicate field in `many_many_extraFields` causing "ClassName" unknown field error HOT 1
- `GridField` escapes HTML content inappropriately HOT 11
- Polymorphic has_many relation query is too ambiguous HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from silverstripe-framework.