Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
Encode PHP constructs to JSON

array
$_options= 'array()'
Additional options used during encoding
array()
Details
__construct(
boolean $cycleCheck
=
false, array $options
=
array()
)
:
void
Constructor
Name | Type | Description |
---|---|---|
$cycleCheck | boolean | Whether or not to check for recursion when encoding |
$options | array | Additional options used during encoding |

_encodeArray(
\array $array
)
:
string
JSON encode an array value
Recursively encodes each value of an array and returns a JSON encoded array string.
Arrays are defined as integer-indexed arrays starting at index 0, where the last index is (count($array) -1); any deviation from that is considered an associative array, and will be encoded as such.
Name | Type | Description |
---|---|---|
$array | \array |
Type | Description |
---|---|
string |

_encodeConstants(
\ReflectionClass $cls
)
:
string
Encode the constants associated with the ReflectionClass parameter. The encoding format is based on the class2 format
Name | Type | Description |
---|---|---|
$cls | \ReflectionClass |
Type | Description |
---|---|
string | Encoded constant block in class2 format |

_encodeDatum(
\mixed $value
)
:
string
JSON encode a basic data type (string, number, boolean, null)
If value type is not a string, number, boolean, or null, the string 'null' is returned.
Name | Type | Description |
---|---|---|
$value | \mixed |
Type | Description |
---|---|
string |

_encodeMethods(
\ReflectionClass $cls
)
:
string
Encode the public methods of the ReflectionClass in the class2 format
Name | Type | Description |
---|---|---|
$cls | \ReflectionClass |
Type | Description |
---|---|
string | Encoded method fragment |

_encodeObject(
object $value
)
:
string
Encode an object to JSON by encoding each of the public properties
A special property is added to the JSON object called '__className' that contains the name of the class of $value. This is used to decode the object on the client into a specific class.
Name | Type | Description |
---|---|---|
$value | object |
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Json_Exception | If recursive checks are enabled and the object has been serialized previously |

_encodeString(
$string
)
:
string
JSON encode a string value by escaping characters as necessary
Name | Type | Description |
---|---|---|
$string |
Type | Description |
---|---|
string |

_encodeValue(
mixed $value
)
:
string
Recursive driver which determines the type of value to be encoded and then dispatches to the appropriate method. $values are either - objects (returns from {@link _encodeObject()}) - arrays (returns from {@link _encodeArray()}) - basic datums (e.g. numbers or strings) (returns from {@link _encodeDatum()})
Name | Type | Description |
---|---|---|
$value | mixed | The value to be encoded |
Type | Description |
---|---|
string | Encoded value |

_encodeVariables(
\ReflectionClass $cls
)
:
string
Encode the public properties of the ReflectionClass in the class2 format.
Name | Type | Description |
---|---|---|
$cls | \ReflectionClass |
Type | Description |
---|---|
string | Encode properties list |

_utf82utf16(
string $utf8
)
:
string
Convert a string from one UTF-8 char to one UTF-16 char.
Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension.
This method is from the Solar Framework by Paul M. Jones
Name | Type | Description |
---|---|---|
$utf8 | string | UTF-8 character |
Type | Description |
---|---|
string | UTF-16 character |

_wasVisited(
mixed $value
)
:
boolean
Determine if an object has been serialized already
Name | Type | Description |
---|---|---|
$value | mixed |
Type | Description |
---|---|
boolean |

encode(
mixed $value, boolean $cycleCheck
=
false, array $options
=
array()
)
:
string
Use the JSON encoding scheme for the value specified
Name | Type | Description |
---|---|---|
$value | mixed | The value to be encoded |
$cycleCheck | boolean | Whether or not to check for possible object recursion when encoding |
$options | array | Additional options used during encoding |
Type | Description |
---|---|
string | The encoded value |

encodeClass(
string $className, string $package
=
''
)
:
string
Encodes the given $className into the class2 model of encoding PHP classes into JavaScript class2 classes.
NOTE: Currently only public methods and variables are proxied onto the client machine
Name | Type | Description |
---|---|---|
$className | string | The name of the class, the class must be instantiable using a null constructor |
$package | string | Optional package name appended to JavaScript proxy class name |
Type | Description |
---|---|
string | The class2 (JavaScript) encoding of the class |
Exception | Description |
---|---|
\Zend_Json_Exception |

encodeClasses(
array $classNames, string $package
=
''
)
:
string
Encode several classes at once
Returns JSON encoded classes, using {@link encodeClass()}.
Name | Type | Description |
---|---|---|
$classNames | array | |
$package | string |
Type | Description |
---|---|
string |