QErrorHandler::VarExport PHP Method

VarExport() public static method

A modified version of var_export to use var_dump via the output buffer, which can better handle recursive structures.
public static VarExport ( mixed $mixData, boolean $blnHtmlEntities = true ) : string
$mixData mixed
$blnHtmlEntities boolean
return string
    public static function VarExport($mixData, $blnHtmlEntities = true)
    {
        if ($mixData instanceof QForm || $mixData instanceof QControl) {
            $mixData->PrepForVarExport();
        }
        ob_start();
        var_dump($mixData);
        $strToReturn = ob_get_clean();
        if ($blnHtmlEntities) {
            if (!extension_loaded('xdebug')) {
                $strToReturn = htmlentities($strToReturn);
            }
        } else {
            if (extension_loaded('xdebug')) {
                $strToReturn = strip_tags(html_entity_decode($strToReturn));
            }
        }
        return $strToReturn;
    }

Usage Example

Example #1
0
sort($__exc_ObjVariableArrayKeys);
$__exc_StrToDisplay = "";
$__exc_StrToScript = "";
foreach ($__exc_ObjVariableArrayKeys as $__exc_Key) {
    if (strpos($__exc_Key, "__exc_") === false && strpos($__exc_Key, "_DATE_") === false && $__exc_Key != "GLOBALS") {
        try {
            if ($__exc_Key == 'HTTP_SESSION_VARS' || $__exc_Key == '_SESSION') {
                $__exc_ObjSessionVarArray = array();
                foreach (${$__exc_Key} as $__exc_StrSessionKey => $__exc_StrSessionValue) {
                    if (strpos($__exc_StrSessionKey, 'qform') !== 0) {
                        $__exc_ObjSessionVarArray[$__exc_StrSessionKey] = $__exc_StrSessionValue;
                    }
                }
                $__exc_StrVarExport = htmlentities(var_export($__exc_ObjSessionVarArray, true));
            } else {
                $__exc_StrVarExport = QErrorHandler::VarExport($__exc_ObjVariableArray[$__exc_Key]);
            }
            $__exc_StrToDisplay .= sprintf("  <a href=\"javascript:RenderPage(%s)\" title=\"%s\">%s</a>\n", $__exc_Key, $__exc_StrVarExport, $__exc_Key);
            $__exc_StrToScript .= sprintf("  %s = \"<pre>%s</pre>\";\n", $__exc_Key, QErrorHandler::PrepDataForScript($__exc_StrVarExport));
        } catch (Exception $__exc_objExcOnVarDump) {
            $__exc_StrToDisplay .= sprintf("  Fatal error:  Nesting level too deep - recursive dependency?\n", $__exc_objExcOnVarDump->Message);
        }
    }
}
_p($__exc_StrToDisplay . '</pre>', false);
printf('<script type="text/javascript">%s</script>', $__exc_StrToScript);
?>
			</div><br />
			<hr width="100%" size="1" color="#dddddd" />
			<center><em>
				<?php