Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

PHP WTF

4,594 views

Published on

PHP is a funny language, this lightning talk shows some of the funnyness.

Published in: Software
  • Same with the float math. JS: "0.1 * 0.1 == 0.01" is false. For exact stuff, use an exact datatype.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • The post increment code is funny, disgusting, and correct. JS does the same in Chrome's console: "a=4; a+++a++" => 9 and "a=4; ++a + ++a" => 11.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

PHP WTF

  1. 1. PHP WTH A short tour of pain & fire.
  2. 2. list() list($a, $a) = array(1, 2, 3, 4); echo $a; // 1 // WTH
  3. 3. in_array() $a = array('7.1'); $exists = in_array('7.10', $a); var_dump($exists); // true // WTH
  4. 4. Private ORLY class 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
  5. 5. == $a = 0; $b = 'x'; false == $a; // true $a == $b; // true $b == true; // true // FFFFFFUUUUUU
  6. 6. Post increment $a = 4; echo $a+++$a++; // 9 // WAT
  7. 7. Floats $a = 0.1 * 0.1; var_dump($a); // double(0.01) var_dump($a == 0.01); // false // ARRRRRGGGG
  8. 8. Ternaries echo (true ? 'Foo' : false ? 'Bar' : ‘Baz' ); // Bar // NOOOOOO
  9. 9. Be Careful

×