/** * @param string[]|null $options JSON encode option * * @return string */ public function toJson(array $options = null) { static $defaultOptions = null; if (null === $options) { if (null === $defaultOptions) { $defaultOptions = Utils::calculateBitmask(array('JSON_PRETTY_PRINT', 'JSON_NUMERIC_CHECK')); } $options = $defaultOptions; } else { $options = Utils::calculateBitmask($options); } return json_encode($this->toArray(), $options); }
public function toJson() { static $options = null; if (null === $options) { $options = Utils::calculateBitmask(array('JSON_PRETTY_PRINT', 'JSON_NUMERIC_CHECK')); } $output = new \SplFixedArray(count($this)); foreach ($this as $index => $token) { $output[$index] = $token->toArray(); } $this->rewind(); return json_encode($output, $options); }