Fully Qualified Name: | Laminas\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 Laminas\Json\Json can contain native JavaScript expressions.
Example:
$foo = array(
'integer' => 9,
'string' => 'test string',
'function' => Laminas\Json\Expr(
'function () { window.alert("javascript function encoded by Laminas\Json\Json") }'
),
);
echo Laminas\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 Laminas\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.