Weird PHP behavior: won't assign the integer 8 to a variable

后端 未结 5 448
灰色年华
灰色年华 2021-01-28 13:18

I think I just encountered the strangest \'bug\' I\'ve ever encountered in my short developer life. It seems like I just can\'t assign the value eight to any variable. For exemp

5条回答
  •  Happy的楠姐
    2021-01-28 14:11

    In PHP, a number that's prefaced by a zero is considered to be octal. Because octal (base 8) only has digits 0-7, 08 is invalid and treated as zero.

    See this manual page for more information, and note the warning in the syntax section: "If an invalid digit is given in an octal integer (i.e. 8 or 9), the rest of the number is ignored."

    
    

提交回复
热议问题