PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php class LOL { static function php($n) { return $n + 1; } } // # LOL 1. Needs extremely ugly hack to work var_dump(array_map([LOL::class, 'php'], [1,2,3])); // #LOL 2. Can literally pass anything as params // we get null as a result. Docs say we get a closure or false. $superlol = Closure::bind(static function($n) { return $n + 1; }, new LogicException(), 'WHATS THE MEANING OF LIFE, PHP?'); // #LOL 3. Array map accepts NULL as value. Making is a no-op, returing the input as is. // https://www.theverge.com/2016/5/5/11592622/this-is-fine-meme-comic var_dump(array_map($superlol, [1,2,3])); // # LOL 4. Needs an even more extremely ugly hack to work $superlol2 = Closure::bind(static function($n) { return $n + 1; }, null, 'LOL'); var_dump(array_map($superlol2, [1,2,3])); // # LOL 5. Final nail in the coffin. Need to use another hack, // to get it working. Because PHP arrays are the broken by design $houseIsBurning = array_filter(array_map($superlol2, [1,2,3]), function($n) { return $n % 2 == 0; }); var_dump($houseIsBurning[0]); // Should be 2 var_dump($houseIsBurning[1]); // LOLPHP $houseIsBurning = array_values($houseIsBurning); var_dump($houseIsBurning[0]); // Should be 2 var_dump($houseIsBurning[1]); // Should be 4
Show:  
Copy Clear