Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- An error is thrown when an unsupported type is encoded --FILE-- <?php $resource ..

Decoded Output download

--TEST--
An error is thrown when an unsupported type is encoded
--FILE--
<?php

$resource = fopen(__FILE__, "r");

var_dump($resource);

var_dump(json_encode($resource));
var_dump(json_last_error(), json_last_error_msg());

var_dump(json_encode($resource, JSON_PARTIAL_OUTPUT_ON_ERROR));
var_dump(json_last_error(), json_last_error_msg());

?>
--EXPECTF--
resource(%d) of type (stream)
bool(false)
int(8)
string(21) "Type is not supported"
string(4) "null"
int(8)
string(21) "Type is not supported"

Did this file decode correctly?

Original Code

--TEST--
An error is thrown when an unsupported type is encoded
--FILE--
<?php

$resource = fopen(__FILE__, "r");

var_dump($resource);

var_dump(json_encode($resource));
var_dump(json_last_error(), json_last_error_msg());

var_dump(json_encode($resource, JSON_PARTIAL_OUTPUT_ON_ERROR));
var_dump(json_last_error(), json_last_error_msg());

?>
--EXPECTF--
resource(%d) of type (stream)
bool(false)
int(8)
string(21) "Type is not supported"
string(4) "null"
int(8)
string(21) "Type is not supported"

Function Calls

fopen 1
var_dump 1

Variables

$resource True

Stats

MD5 029aeb828af9d966c6da7f9800cc8a79
Eval Count 0
Decode Time 83 ms