Skip to content

Instantly share code, notes, and snippets.

@Vinai
Created October 9, 2014 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vinai/0f9df543b4b7f93e1f1a to your computer and use it in GitHub Desktop.
Save Vinai/0f9df543b4b7f93e1f1a to your computer and use it in GitHub Desktop.
PHP use statements don't have to refer to existing classes
<?php
namespace Random\Example;
spl_autoload_register(function($class) {
echo "Autoload triggered for class $class\n";
});
echo "Importing class with use upcoming...\n";
use Some\Example\Nonexistant\Class\Which\Will\Not\Trigger\The\Autoloader;
echo "use namespace done, autoloader not triggered so far\n";
echo "class_exists with autoloader upcoming...\n";
class_exists('Nonexistant');
echo "class_exisis with autoloader done\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment