Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

PHPize.online is a free online environment for quickly running, experimenting with and sharing PHP (including Carbon extension for DateTime) and SQL code. You can run your SQL code with PHP code that can use the same DB. For database manipulations you can use pre-defined instances of PDO ($pdo), mysqli ($mysqli) & Laravel query builder ($db)

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