Skip to content

Instantly share code, notes, and snippets.

@TorbenKoehn
Created July 7, 2016 15:34
Show Gist options
  • Select an option

  • Save TorbenKoehn/25efaf5edbc9191d762776a4e366cee5 to your computer and use it in GitHub Desktop.

Select an option

Save TorbenKoehn/25efaf5edbc9191d762776a4e366cee5 to your computer and use it in GitHub Desktop.
<?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