Increment behavior on strings - PHP easter egg?

后端 未结 3 375
灰色年华
灰色年华 2020-12-11 17:24
$var = \'test_1\';
var_dump(++$var); // string(6) \"test_2\" 

$var2 = \'1_test\';
var_dump(++$var2); // string(6) \"1_tesu\"

$var3 = \'test_z\';
var_dump(++$var3);         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 17:44

    It's not an Easter egg. It's expected in PHP, but no it's not common in other languages. (At least not incrementing letters.) PHP treats strings containing a number the same as numbers in most cases. So you can also "2" * "2" for example.

提交回复
热议问题