[wp-trac] [WordPress Trac] #25280: wp_localize_script unexpectedly convert numbers to strings
WordPress Trac
noreply at wordpress.org
Thu Sep 12 05:27:19 UTC 2013
#25280: wp_localize_script unexpectedly convert numbers to strings
-----------------------------+------------------------------
Reporter: adamsilverstein | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch close |
-----------------------------+------------------------------
Comment (by c3mdigital):
Replying to [comment:3 adamsilverstein]:
>
> interesting points, thanks for the feedback! the boolean evaluation in
JS won't change, right? "1" and 1 are both truthy.
>
> the patch does not rely on PHP 5.3; instead it improves the behavior of
if 5.3 is available. in 5.2 nothing changes.
>
> agree wp_localize_script is not intended for this purpose, but in
practice thats how its used- even internally by core. if we aren't going
to try to fix the function, how about adding a new function for passing
non-string values from php to js - providing a standard method is better
than leaving it up to developers in my opinion.
Also those results were after the booleans and numbers were run through
html_entity_decode cast as a string. I don't fully understand why scaler
variables are run through html_entity_decode()?
I would love a better way to pass data to javascript as a script
dependency. wp_localize_script would be fine for most use if there was a
way to pass a real boolean. Maybe we could start with omitting booleans
from the is_scalar check. I'm not against JSON_NUMERIC_CHECK but know core
doesn't like to use stuff dependent on php 5.3 even if there is a sanity
check.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25280#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list