Class Expr

Summary

Fully Qualified Name: Zend\Json\Expr

Description

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")} }

Methods

Name Description Defined By
__construct() Expr
__toString() Cast to string Expr

Method Details

__construct()

Parameter Name Type Description
$expression string The

Returns:

__toString()

Cast to string

Returns: string holded javascript expression.

Top