Fully Qualified Name: | Zend\Json\Expr |
Encode a string to a native JavaScript expression.
This class simply holds a string with a native JavaScript expression, so objects or arrays to be encoded with Zend\Json\Json can contain native JavaScript expressions.
Example:
$foo = array(
'integer' => 9,
'string' => 'test string',
'function' => Zend\Json\Expr(
'function () { window.alert("javascript function encoded by Zend\Json\Json") }'
),
);
echo Zend\Json\Json::encode($foo, false, ['enableJsonExprFinder' => true]);
The above returns the following JSON (formatted for readability):
{
"integer": 9,
"string": "test string",
"function": function () {window.alert("javascript function encoded by Zend\Json\Json")}
}
Name | Description | Defined By |
---|---|---|
__construct() | Expr | |
__toString() | Cast to string | Expr |
Parameter Name | Type | Description |
---|---|---|
$expression | string | The |
Returns:
Cast to string
Returns: string holded javascript expression.