-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG]: Default value ignored in Phalcon\Config #15370
Comments
I see where the issue is. The question though is what happens if you want to have a Personally I see this as a documentation omission not a bug. |
I see and it's hard to discuss about this. Sure, internally you can distinguish between a non-existing key and and key that is set to
Looking from application perspective So, for both cases I cannot distinguish for which reason I get Additionally, the definition of The dilemma is now, that many people, which have migrated their projects from v3 to v4 might rely on the old behavior, like me. |
The v3 version allowed you to ignore To check if a key exists one has to use One can easily extend the @Jeckerson thoughts? |
As @niden mentioned, if you want to use
In PHP, |
I understand your intention. But I believe the most people have such a use case like "get config value and return fallback if empty". If I really want to know, if a config value is not set explicitely, I would have to use But the decision has been made by Phalcon team. Thanks nevertheless. BTW: I love you guys for your work, so my disagreement to your decision does not affect my love to Phalcon ;-) |
@wurst-hans Revisiting this one. Current behavior: $data = [
"one" => "value",
"two" => "",
"three" => null,
];
$collection = new Collection($data);
// Exists
var_dump($collection->get("one", "fallback"));
// "value"
// Exists = empty string
var_dump($collection->get("two", "fallback"));
// ""
// Exists = null
var_dump($collection->get("three", "fallback"));
// null
// Does not exist
var_dump($collection->get("four", "fallback"));
// "fallback" Proposed/old behavior $data = [
"one" => "value",
"two" => "",
"three" => null,
];
$collection = new Collection($data);
// Exists
var_dump($collection->get("one", "fallback"));
// "one"
// Exists = empty string
var_dump($collection->get("two", "fallback"));
// "fallback"
// Exists = null
var_dump($collection->get("three", "fallback"));
// "fallback"
// Does not exist
var_dump($collection->get("four", "fallback"));
// "fallback" And your assertion is that we should keep the second option using Did I get this right? |
No, because v3 uses
So, IMO, the old behavior is better than the current:
I don't remember correctly, why we are talking about |
Resolved in #15811 |
In Phalcon v4.1.0 it is not possible to use defaultValue in method
get
of Config component. It only works, when the requested config key does not exist really.In v4 the Config class extends Collection. When looking at code it seems, that default value is returned only, when key cannot be fetched (i.e., it does not exist). In v3 one can see that default value is returned always, when property is not set. So, in v3 it returns default value even when existing config key value is set to
null
.I expect in v4 that a
$config->get('somekey', 'fallback');
will returnfallback
whensomekey
is not defined or is set tonull
.This is the commit, where behavior had been changed.
The text was updated successfully, but these errors were encountered: