[wp-trac] [WordPress Trac] #25280: wp_localize_script unexpectedly converts numbers to strings

WordPress Trac noreply at wordpress.org
Thu Sep 24 14:37:39 UTC 2015


#25280: wp_localize_script unexpectedly converts numbers to strings
------------------------------------+-----------------------------
 Reporter:  adamsilverstein         |       Owner:
     Type:  enhancement             |      Status:  new
 Priority:  normal                  |   Milestone:  Future Release
Component:  I18N                    |     Version:  3.2
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:  javascript
------------------------------------+-----------------------------

Comment (by jtsternberg):

 Replying to [comment:29 Fab1en]:
 > * in JavaScript, check that the variable has been transformed to a
 string (whereas you should normally expect it to be an integer)

 Most javascript linters expect strict type-checking, so yes, every time I
 use the values to compare, I check strictly, as a string, because that is
 what is always provided by wp_localize_script.

 > If this is really what you are doing (checking that an integer is
 transformed into a string), you just have to wrap the integer into a
 string in PHP to fix this.

 Yes, I know how to fix my scripts/code. My point is for all the
 unsuspecting victims who are type-checking strictly and have no idea this
 change is in the works. That's what back-compatibility is all about.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/25280#comment:30>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list