JSON 定数をハンドラーから JSON にシリアライズしたいオブジェクトに渡そうとしています。次のコードを試すと:
class AJAXHandler {
public function getPrettyPrint() {
$jh = new JSONHandler();
$jh->getJSON(JSON_PRETTY_PRINT | JSON_FORCE_OBJECT);
}
}
class JSONHandler {
protected $id;
protected $name;
public function getJSON($json_constants) {
if (isset($json_constants)) {
return json_encode(get_object_vars($this), $json_constants);
} else {
return json_encode(get_object_vars($this));
}
}
}
私は得る:
Message: Use of undefined constant JSON_PRETTY_PRINT - assumed 'JSON_PRETTY_PRINT'
これは可能ですか?