Zend Framework  3.0
Public Member Functions | Protected Attributes | List of all members
Expr Class Reference

Encode a string to a native JavaScript expression. More...

Public Member Functions

 __construct ($expression)
 
 __toString ()
 Cast to string.
 

Protected Attributes

 $expression
 

Detailed 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 can contain native JavaScript expressions.

Example:

$foo = array( 'integer' => 9, 'string' => 'test string', 'function' => Zend( 'function () { window.alert("javascript function encoded by Zend\Json\Json") }' ), );

echo Zend::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")} }

Constructor & Destructor Documentation

__construct (   $expression)
Parameters
string$expressionThe expression to represent.

Member Function Documentation

__toString ( )

Cast to string.

Returns
string holded javascript expression.

Member Data Documentation

$expression
protected