Class Expr

Summary

Fully Qualified Name: Laminas\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 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")} }

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