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
class Dummy extends Singleton { | |
constructor() { | |
super(); | |
this.i = 0; | |
} | |
incr() { ++this.i; } | |
} |
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 | |
function compact_number_format(float $num , int $decimals = 2 , ?string $decimal_separator = '.' , ?string $thousands_separator = ','): string { | |
$r = number_format($num, $decimals, $decimal_separator, $thousands_separator); | |
if ($decimals === 0) { | |
return $r; | |
} | |
return rtrim(rtrim($r, '0'), $decimal_separator); | |
} |
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
# 1- Make a helper file and put following code in there | |
# 2- Auto-load it | |
# 3- call `register_ci_instance($this)` at the very beginning in your base controller | |
# 4- use `$ci = &get_instance()` anywhere you want. FYI: I'm not sure if `&` is even necessary when calling `get_instance`. | |
# Also, you may change `\App\Controllers\BaseController` for better IDE autocomplete support. | |
# Tested on PHP8 | |
<?php | |
$CI_INSTANCE = []; # It keeps a ref to global CI instance |