Skip to content

Instantly share code, notes, and snippets.

@felipecwb
Last active August 29, 2015 14:15
Show Gist options
  • Save felipecwb/2e747b1a69e133baa188 to your computer and use it in GitHub Desktop.
Save felipecwb/2e747b1a69e133baa188 to your computer and use it in GitHub Desktop.
Functional PHP with goal challenge.
<?php
/*
* Now with uniform variable syntax (https://wiki.php.net/rfc/uniform_variable_syntax)
* We can do this nice things like in others languages.
*
* Tested in:
* $ php -v
* > PHP 7.0.0-dev (cli) (built: Feb 11 2015 02:07:44)
* > Copyright (c) 1997-2015 The PHP Group
* > Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
* > with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
*/
function g($a = null, $s = 'g') {
$s .= $a ?: 'o';
return $a ? $s : function ($a = null) use ($s) {
return g($a, $s);
};
}
(function () {
print g('al') . PHP_EOL
. g()('al') . PHP_EOL
. g()()()('al') . PHP_EOL
. g()()()()()('al') . PHP_EOL
. g()()()()()()('al') . PHP_EOL
. g()()()()()()()('al') . PHP_EOL
. g()()()()()()()()('al') . PHP_EOL;
})();
@felipecwb
Copy link
Author

hahahaha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment