Created
June 1, 2023 16:53
-
-
Save kagg-design/4da52aec73353cec33df3f45525b3c3c 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 | |
class FooClass { | |
public static function get_instance() { | |
static $instance; | |
if ( ! $instance ) { | |
$variant = 'A'; | |
switch ( $variant ) { | |
case 'A': | |
$instance = ( new self() )->init(); | |
break; | |
case 'B': | |
$instance = new self(); | |
$instance->init(); | |
break; | |
} | |
} | |
return $instance; | |
} | |
private function init() { | |
$a = foo_func(); | |
return $this; | |
} | |
} | |
function foo_func() { | |
return FooClass::get_instance(); | |
} | |
foo_func(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment