<?php
$foo = "0"; // $foo is string (ASCII 48)
$foo += 2; // $foo is now an integer (2)
$foo = $foo + 1.3; // $foo is now a float (3.3)
$foo = 5 + "10 Tiny Wangs"; // $foo is integer (15)
$foo = 5 + "10 Monstrous Cocks"; // $foo is integer (15)
?>
You cannot do that, that goes against the teachings of dead dogs!
Name:
Anonymous2009-06-29 16:29
um. okay.
Name:
Anonymous2009-06-29 17:10
$ php -r "echo 0.15-0.05;"
0.0:
Name:
Anonymous2009-06-29 19:04
Type coercion isn't necessarily a bad thing, but PHP does go overboard.
It combines particularly nicely with the fact that the concatenation operator is . and not + like in every other language. You get hilariously nonsensical errors if you mess them up, e.g. in SQL queries.
But who need prepared statements?
Name:
Anonymous2009-06-29 19:08
Any language that has a string concatenation operator does not deserve respect.
>>4
Using + for concatenation is fucking retarded. It's wrong for an operator to radically change behavior just because you passed it a different type.
Name:
Anonymous2009-06-29 19:23
>>5
This. String concatenation should always be a function so it's clear to the maintainer what's going on.
Name:
Anonymous2009-06-29 20:29
>>7
For template languages that doesn't make sense. I wouldn't be opposed to having ++ as the concatenation operator, but concatenate($string1, $string2) would hurt.
More so than PHP already does.
Name:
Anonymous2009-06-29 20:36
>>5
More like any language that doesn't have a dedicated string concatenation operator doesn't deserve respect?
It's easy to understand when there are separate operators for addition and string concatenation, like ++ in Haskell or .. in Lua or & in VB.
Also, using + for string concatenation is ok as long as a language has a sane type system and doesn't implicitly coerce values.
also it's nearly 2 am here and I'm probably not writing proper english but fuck it