types - Increment behavior on strings - PHP easter egg? -


$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); // string(6) "test_a"  $var4 = 'test_'; var_dump(++$var4); // string(5) "test_" 

so apparently, using increment operator on string has effect of increasing digit if last character number, increasing letter , resetting once z if last character in alphabet, , has no effect on non alpha numeric characters.

is standard feature, expected in many scripting languages, or did find php easter egg?

php follows perl's convention when dealing arithmetic operations on character variables , not c's. example, in php , perl $a = 'z'; $a++; turns $a 'aa', while in c = 'z'; a++; turns '[' (ascii value of 'z' 90, ascii value of '[' 91). note character variables can incremented not decremented , plain ascii characters (a-z , a-z) supported. incrementing/decrementing other character variables has no effect, original string unchanged.

-> http://php.net/manual/en/language.operators.increment.php


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -