#25668 closed defect (bug) (invalid)
selected, checked functions
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | reporter-feedback close |
Focuses: | Cc: |
Description
The selected / checked functions (from general-template.php.) are not working 100% properly. They do return the desired value when called but if you want to use them as an echo, they also get called. I tested with 2 exact strings and the non-echo version still get's returned. Basically, you get the echo and the non-echo at once.
Change History (18)
#1
@
11 years ago
- Component changed from Validation to General
- Keywords reporter-feedback added
- Severity changed from major to normal
#2
@
11 years ago
These functions both employ the __checked_selected_helper()
function. This function returns the result regardless of whether it echo's it. I don't see why that would cause a problem though, unless you did this:
echo checked( $checked, $current, true );
That would echo the result twice, but it would be caused by using an extra unnecessary echo
.
#4
follow-ups:
↓ 5
↓ 8
@
11 years ago
It's not really PHP behavior. I guess it would be nice to not return the value on echo but it isn't a big issue.
#5
in reply to:
↑ 4
@
11 years ago
Replying to markoheijnen:
It's not really PHP behavior. I guess it would be nice to not return the value on echo but it isn't a big issue.
How can I fix it and submit a patch?
#7
in reply to:
↑ 6
@
11 years ago
Replying to markoheijnen:
See http://make.wordpress.org/core/handbook/
For patch see: http://make.wordpress.org/core/handbook/submitting-a-patch/
Thank you!
#8
in reply to:
↑ 4
;
follow-up:
↓ 9
@
11 years ago
Replying to markoheijnen:
I guess it would be nice to not return the value on echo but it isn't a big issue.
Why? I don’t see a bug or even a problem here. If you need the return value as a string, you can get it. And if you want to print it out, that works too.
We don’t even know if a change would break existing code. Let’s say someone is using the current behavior to reuse the return value:
$check = checked( $checked, $current, true ); // create the next form field then: echo $check;
Not very likely, but possible. The current state works, we shouldn’t change it without a real benefit.
#9
in reply to:
↑ 8
;
follow-up:
↓ 10
@
11 years ago
Replying to toscho:
Replying to markoheijnen:
I guess it would be nice to not return the value on echo but it isn't a big issue.
Why? I don’t see a bug or even a problem here. If you need the return value as a string, you can get it. And if you want to print it out, that works too.
We don’t even know if a change would break existing code. Let’s say someone is using the current behavior to reuse the return value:
$check = checked( $checked, $current, true ); // create the next form field then: echo $check;Not very likely, but possible. The current state works, we shouldn’t change it without a real benefit.
Ithe checked function is using the __checked_selected_helper
function and in it, the $echo
variable is under a if. Basically, if it's set to true, it echoes the string as it should, but if it is not set, it still echoes. $echo does not have a default value.
If using that code you mentionedm you should get printed checked='checked'
twice. That is not normal.
#10
in reply to:
↑ 9
;
follow-up:
↓ 12
@
11 years ago
Replying to ciapci:
Ithe checked function is using the
__checked_selected_helper
function and in it, the $echo variable is under a if. Basically, if it's set to true, it echoes the string as it should, but if it is not set, it still echoes.
No, it doesn’t. $echo
is a required parameter here, if you don’t pass a value for it, you get a PHP error. And if it is false
, nothing is printed.
If using that code you mentionedm you should get printed checked='checked' twice. That is not normal.
You control both places where the return value is printed. Try it. This is exactly what you can expect from the existing code.
#12
in reply to:
↑ 10
;
follow-up:
↓ 15
@
11 years ago
Replying to toscho:
Replying to ciapci:
Ithe checked function is using the
__checked_selected_helper
function and in it, the $echo variable is under a if. Basically, if it's set to true, it echoes the string as it should, but if it is not set, it still echoes.
No, it doesn’t.
$echo
is a required parameter here, if you don’t pass a value for it, you get a PHP error. And if it isfalse
, nothing is printed.
If using that code you mentionedm you should get printed checked='checked' twice. That is not normal.
You control both places where the return value is printed. Try it. This is exactly what you can expect from the existing code.
I used this code: http://d.pr/i/MMnc and I'm getting this: http://d.pr/i/HaYl.
It only shows once if I remove the true and the echo. But I need to set the result as a variable.
#14
in reply to:
↑ 13
@
11 years ago
Replying to markoheijnen:
Then your code is wrong. You can also see it as a feature ;)
my code is wrong because I need it as a variable? I'm working inside a string. I need it to echo because it's supposed to be something like $output .='string'.checked('aaa','aaa',true).'string'; I get an extra checked='checked'.
Why is my code wrong?
#15
in reply to:
↑ 12
@
11 years ago
Replying to ciapci:
I used this code: http://d.pr/i/MMnc and I'm getting this: http://d.pr/i/HaYl.
It only shows once if I remove the true and the echo. But I need to set the result as a variable.
Then set the last parameter to false
. Your code is wrong, not checked()
.
#16
@
11 years ago
hmm... I'm a little embarrassed right now.
I'm just going to say Sorry! and THANKS!
And we'll leave it at that, shall we?
Could you provide a piece of code to reproduce the issue?