Last active
January 4, 2016 03:09
-
-
Save nicolas-grekas/8559504 to your computer and use it in GitHub Desktop.
Playing for PPP for native PHP function overloading
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
git clone https://github.com/nicolas-grekas/Patchwork-PHP-Parser.git ppp | |
cd ppp | |
./bin/ppp t1.php #see below for t1.php (and t2.php, required by t1.php) |
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
<?php | |
function abc($s) | |
{ | |
return strlen($s) * strlen($s); | |
} | |
function def(&$a = 5) | |
{ | |
$a = 'oups'; | |
return 12; | |
} | |
// Patchwork\Shim is not a real function but a parser macro | |
// that takes the replaced function as first arg | |
// the replacement function as second | |
// and the parameters signatures (with optional default value/reference) | |
// Of course these remplacement are useless and for demo purpose only. | |
// See https://github.com/nicolas-grekas/Patchwork/blob/master/core/compat/bootup.patchwork.php | |
// for more useful uses of the feature. | |
Patchwork\Shim(strlen, abc, $s); | |
Patchwork\Shim(count, def, &$a = 5); | |
include "./t2.php"; |
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
<?php | |
$var = 'vvv'; | |
echo strlen($var), "\n"; | |
echo count($var), "\n"; | |
echo $var, "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment