Created
July 7, 2016 15:34
-
-
Save TorbenKoehn/25efaf5edbc9191d762776a4e366cee5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| declare(autobox='MyAutoboxer::box'); | |
| //All variables coming into this file will be handled through autoboxing | |
| class Autoboxer | |
| { | |
| public static function box(mixed $value) | |
| { | |
| if (is_string($value)) | |
| return new StringObject($value); | |
| if (is_array($value)) | |
| return new ArrayObject($value); | |
| return $value; | |
| } | |
| } | |
| //I really don't know how to handle normal typehints like "string" yet. | |
| $someString = "someString"; //Autoboxing kicks in automatically and returns `new StringObject("someString")` | |
| if ($someString->equals("someOtherString")) | |
| echo $someString->format("I am %s!"); | |
| "a b c d e"->explode(' ')->map('strtoupper')->each(function($letter) { | |
| echo $letter; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment