I need to encode a javascript function into a JSON object in PHP.
This:
$function = \"function(){}\"; $message = \"Hello\"; $json = array(
No. JSON spec does not support functions. You can write your own code to output it in a JSON-like format and it should work fine though.