Fix var_export() not working for stdClass in PHP < 7.3

This commit is contained in:
Kijin Sung 2018-12-13 15:22:11 +09:00
parent a2c9274681
commit 3f7f802585
8 changed files with 40 additions and 43 deletions

View file

@ -409,6 +409,22 @@ function url2path($url)
return Rhymix\Framework\URL::toServerPath($url);
}
/**
* This function fixes some of the issues with var_export() so that the result executes cleanly.
*
* @param mixed $var
* @return string
*/
function var_export_clean($var)
{
$result = var_export($var, true);
if (version_compare(PHP_VERSION, '7.3', '<'))
{
$result = preg_replace('/stdClass::__set_state\((?=array\(\n)/', '(object)(', $result);
}
return $result;
}
/**
* Convert hexadecimal color codes to an array of R, G, B values.
* This function can handle both 6-digit and 3-digit notations, optionally prefixed with '#'.