Skip to content

Instantly share code, notes, and snippets.

@nikic
Created January 24, 2013 23:37
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nikic/4629662 to your computer and use it in GitHub Desktop.
Save nikic/4629662 to your computer and use it in GitHub Desktop.
<?php
error_reporting(E_ALL);
class StringTypeHandler {
public function length() {
return strlen($this);
}
}
register_primitive_type_handler(6 /* IS_STRING */, "StringTypeHandler");
$str = "str";
var_dump($str->length()); // int(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment