Created
September 16, 2015 08:48
-
-
Save FLamparski/92c876599c2d75acc94f to your computer and use it in GitHub Desktop.
In PHP, functions "are" "first" "class" "objects"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Psy Shell v0.4.4 (PHP 5.6.4-4ubuntu6.2 — cli) by Justin Hileman | |
>>> function foo($x) { return $x * 2; } | |
=> null | |
>>> foo(5) | |
=> 10 | |
>>> is_callable(foo) | |
PHP error: Use of undefined constant foo - assumed 'foo' on line 1 | |
>>> is_callable('foo') | |
=> true | |
>>> 'foo'(5) | |
PHP Parse error: Syntax error, unexpected '(' on line 1 | |
>>> ('foo')(5) | |
PHP Parse error: Syntax error, unexpected '(' on line 1 | |
>>> $bar = 'foo'; | |
=> "foo" | |
>>> is_callable($bar) | |
=> true | |
>>> $bar(5) | |
=> 10 | |
>>> is_callable('array_map') | |
=> true | |
>>> $map = 'array_map'; | |
=> "array_map" | |
>>> $map($bar, [1, 2, 3]) | |
=> [ | |
2, | |
4, | |
6 | |
] | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment