[wp-trac] Re: [WordPress Trac] #4005: php-gettext's plural forms parsing is broken for nplurals>2

WordPress Trac wp-trac at lists.automattic.com
Sat Mar 24 13:29:44 GMT 2007


#4005: php-gettext's plural forms parsing is broken for nplurals>2
------------------------------+---------------------------------------------
 Reporter:  moeffju           |        Owner:  ryan 
     Type:  defect            |       Status:  new  
 Priority:  high              |    Milestone:  2.2  
Component:  i18n              |      Version:  2.1.2
 Severity:  normal            |   Resolution:       
 Keywords:  has-patch commit  |  
------------------------------+---------------------------------------------
Comment (by moeffju):

 For some additional explanation: PHP evaluates ternary operator
 expressions from left to right. Thus, for Plural-Forms like `nplurals=3;
 plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 ||
 n%100>=20) ? 1 : 2;`:

 for n = 1: (expected: 0, actual: 2)
 {{{
    1%10==1 && 1%100!=11 ? 0 : 1%10>=2 && 1%10<=4 && (1%100<10 ||
 1%100>=20) ? 1 : 2
 => TRUE && TRUE ? 0 : FALSE && TRUE && (TRUE || FALSE) ? 1 : 2
 => (TRUE && TRUE ? 0 : FALSE && TRUE && (TRUE || FALSE)) ? 1 : 2
 => 0 ? 1 : 2
 => 2
 }}}

 Parenthesizing the subexpressions fixes the precedence.

-- 
Ticket URL: <http://trac.wordpress.org/ticket/4005#comment:9>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list