- var_export: documentation ( source)
<?php
function test_val_as_array($val) {
$type = gettype($val);
try {
echo "val before access = ".var_export($val, true)."\n";
echo "accessing $type as array {$val['test']}\n";
$val['test'] = 'wtf';
echo "set $type offset 'test' to string 'wtf'\n";
echo "$type offset 'test' = {$val['test']}\n";
echo "val after access = ".var_export($val, true)."\n";
} catch (Exception $e) {
echo "caught error {$e->getMessage()} when accessing $type as array\n";
}
};
test_val_as_array(null);
test_val_as_array('test');
test_val_as_array(123);
test_val_as_array(true);
test_val_as_array(1.2);
test_val_as_array(new stdClass);