php wtf

Post on 28-Jul-2015

793 Views

Category:

Software

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

PHP WTHA short tour of pain & fire.

list()

list($a, $a) = array(1, 2, 3, 4); echo $a; // 1 // WTH

in_array()

$a = array('7.1'); $exists = in_array('7.10', $a); var_dump($exists); // true // WTH

Private ORLYclass Human { private $name; function __construct($name) { $this->name = $name; } public function touch($human) { echo “Touched $human->name”; } }

$sally = new Human(‘sally’); $joe = new Human(‘joe’); $sally->touch($joe); // Touched joe

==$a = 0; $b = 'x'; false == $a; // true

$a == $b; // true

$b == true; // true // FFFFFFUUUUUU

Post increment

$a = 4; echo $a+++$a++; // 9 // WAT

Floats

$a = 0.1 * 0.1; var_dump($a); // double(0.01)

var_dump($a == 0.01); // false // ARRRRRGGGG

Ternaries

echo (true ? 'Foo' : false ? 'Bar' : ‘Baz' ); // Bar // NOOOOOO

Be Careful

top related