Last active
December 14, 2023 00:07
-
-
Save pematt/fb244e026992b2d8a8f353a14d59b575 to your computer and use it in GitHub Desktop.
Pretty print php objects. Need php 7.2 or newer.
This file contains hidden or 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 | |
// Returns a string containing the type, and value in prettyfied JSON, of the argument. | |
function pretty ($var) { | |
return gettype($var) . ' ' . json_encode( | |
$var, | |
JSON_UNESCAPED_SLASHES | // Don't escape forward slashes. stripslashes() could be used afterwards instead | |
JSON_UNESCAPED_UNICODE | // Print unicode characters insteas of their encoding "€" vs "\u20ac" | |
JSON_PRETTY_PRINT | // Nice layout over several lines, human readable | |
JSON_PARTIAL_OUTPUT_ON_ERROR | // Substitute whatever can not be printed | |
JSON_INVALID_UTF8_SUBSTITUTE // Convert invalid UTF-8 characters to \0xfffd (Unicode Character 'REPLACEMENT CHARACTER') | |
); // Constants: https://www.php.net/manual/en/json.constants.php | |
} | |
$argsObj = (object) [ | |
'operation' => 'acquireNext', | |
'args' => [ | |
'workerIntegration' => 1, | |
'workerType' => '2', | |
'jobStatus' => 'scheduled' | |
], | |
'caller' => __FILE__ . ':' . __LINE__ | |
]; | |
echo "argsObj pretty: " . pretty($argsObj) . PHP_EOL; | |
echo "print_r: "; | |
print_r($argsObj); | |
echo "var_dump: "; | |
var_dump($argsObj); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment