Skip to content

Instantly share code, notes, and snippets.

@magickatt
Created August 13, 2013 17:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magickatt/6223818 to your computer and use it in GitHub Desktop.
Save magickatt/6223818 to your computer and use it in GitHub Desktop.
Late Static Binding namespace resolution in PHP
<?php
/*
* "Late Static Binding" namespace
*/
$class = get_called_class();
$lastSlashPosition = strrpos($class, '\\');
$namespace = substr($class, 0, $lastSlashPosition);
// ... or the shorter version
$namespace = substr(get_called_class(), 0, strrpos(get_called_class(), '\\'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment