View difference between Paste ID: Kje6B5zg and GNBRMA0A
SHOW: | | - or go back to the newest paste.
1
trait BinarySafetyTrait
2
{
3
    protected static $originalEncoding = "utf-8"; // Значение по умолчанию
4
5
    protected static function enableBinarySafety()
6
    {
7
        static::$originalEncoding = mb_internal_encoding();
8
        mb_internal_encoding("latin1");
9
    }
10
11
    protected static function disableBinarySafety()
12
    {
13
        mb_internal_encoding(static::$originalEncoding);
14
    }
15
16
    protected static function executeInBinarySafeEnvironment($callback)
17
    {
18
        static::enableBinarySafety();
19
20
        try {
21
            return call_user_func($callback);
22
        } finally {
23
            static::disableBinarySafety();
24
        }
25
    }
26
}