Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created March 31, 2013 18:08
Show Gist options
  • Select an option

  • Save philsturgeon/5281485 to your computer and use it in GitHub Desktop.

Select an option

Save philsturgeon/5281485 to your computer and use it in GitHub Desktop.
PHP, you crazy bitch.
php > $i = '';
php > var_dump(++$i);
string(1) "1"
php > var_dump(++$i);
int(2)
php > var_dump(++$i);
int(3)
@dragoonis
Copy link
Copy Markdown

Empty string casted to an integer is 0 dude. Lets move on :D

What is interesting is the "1" then int(2). I know why it does it though.

safe type juggling but no type casting
"" (using numeric operator) "0".

ok you really did mean to play with an existing numeric value, you're now and integer
"0" (using numeric operator) int(1).

@philsturgeon
Copy link
Copy Markdown
Author

Yep, like I said I know what it's doing, but its fucking mental.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment