Skip to content

Instantly share code, notes, and snippets.

@kagg-design
Created June 1, 2023 16:53
Show Gist options
  • Save kagg-design/4da52aec73353cec33df3f45525b3c3c to your computer and use it in GitHub Desktop.
Save kagg-design/4da52aec73353cec33df3f45525b3c3c to your computer and use it in GitHub Desktop.
<?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