= 8.3) {
return json_validate($maybeJSON);
} else {
$obj = json_decode($maybeJSON);
return (json_last_error() === JSON_ERROR_NONE) ? true : false;
}
}
/**
* Will get only the right part of string by length.
* @param string $str
* @param int $length
* @retval type string or false
*/
public static function get_string_right(string $str, int $length): false | string {
return self::string_sub_part($str, -$length);
}
public static function real_time_output(): void {
header("Content-type: text/plain");
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);
while (ob_get_level() > 0) {
// Get the curent level
$level = ob_get_level();
// End the buffering
ob_end_clean();
// If the current level has not changed, abort
if (ob_get_level() == $level) break;
}
}
/**
* Clear out from memory given variable by Reference!
* @param type $sensitive_data
*/
public static function wipe(& $sensitive_data): void {
if (function_exists("sodium_memzero")) {
sodium_memzero($sensitive_data);
}
unset($sensitive_data);
}
/**
* Variable Dump and exit
* Configure of security for show_dumps must be true for debugging.
* @param var - any type will display type and value of contents
* @param bool end - if true ends the script
*/
public static function dump($var = 'nothing', $end = true): void {
if (\CodeHydrater\bootstrap\configure::get('security', 'show_dumps') !== true) {
return;
}
if (!is_object($var)) {
var_dump($var);
echo '
';
}
if ($var === false) {
echo 'It is FALSE!';
} elseif ($var === true) {
echo 'It is TRUE!';
} elseif (is_resource($var)) {
echo 'VAR IS a RESOURCE';
} elseif (is_array($var) && self::get_count($var) == 0) {
echo 'VAR IS an EMPTY ARRAY!';
} elseif (is_numeric($var)) {
echo 'VAR is a NUMBER = ' . $var;
} elseif (empty($var) && !is_null($var)) {
echo 'VAR IS EMPTY!';
} elseif ($var == 'nothing') {
echo 'MISSING VAR!';
} elseif (is_null($var)) {
echo 'VAR IS NULL!';
} elseif (is_string($var)) {
echo 'VAR is a STRING = ' . $var;
} else {
echo "
";
print_r($var);
echo '';
}
echo '