-
-
Save FrankM1/5247742 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Here we are, in any scope imaginable. It doesn't matter which | |
$my_object = new My_Class(); | |
add_filter( 'jpb.provider.my_class', function() use ( $my_object ) { | |
return $my_object || new My_Class(); | |
} ); | |
// This is in the global scope | |
function get_my_class_instance() { | |
$obj = apply_filters( 'jpb.provider.my_class', false ); | |
if( ! $obj ) { | |
throw new Exception( "This is embarassing, isn't it?" ); | |
} | |
return $obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment