Encode PHP constructs to JSON

category Zend
package Zend_Json
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 Methods

Use the JSON encoding scheme for the value specified

encode(mixed $value, boolean $cycleCheck = false, array $options = array()) : string
Static

Parameters

$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

Returns

stringThe encoded value

Encodes the given $className into the class2 model of encoding PHP classes into JavaScript class2 classes.

encodeClass(string $className, string $package = '') : string
Static

NOTE: Currently only public methods and variables are proxied onto the client machine

Parameters

$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

Exceptions

\Zend_Json_Exception

Returns

stringThe class2 (JavaScript) encoding of the class

Encode several classes at once

encodeClasses(array $classNames, string $package = '') : string
Static

Returns JSON encoded classes, using \encodeClass().

Parameters

$classNames

array

$package

string

Returns

string

Encode Unicode Characters to \u0000 ASCII syntax.

encodeUnicodeString(string $value) : string
Static

This algorithm was originally developed for the Solar Framework by Paul M. Jones

link http://solarphp.com/
link http://svn.solarphp.com/core/trunk/Solar/Json.php

Parameters

$value

string

Returns

string

Constructor

__construct(boolean $cycleCheck = false, array $options = array()) : void

Parameters

$cycleCheck

boolean

Whether or not to check for recursion when encoding

$options

array

Additional options used during encoding

JSON encode an array value

_encodeArray(\array& $array) : string

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.

Parameters

$array

\array&

Returns

string

JSON encode a basic data type (string, number, boolean, null)

_encodeDatum(\mixed& $value) : string

If value type is not a string, number, boolean, or null, the string 'null' is returned.

Parameters

$value

\mixed&

Returns

string

Encode an object to JSON by encoding each of the public properties

_encodeObject(object $value) : string

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.

Parameters

$value

object

Exceptions

\Zend_Json_Exception If recursive checks are enabled and the object has been serialized previously

Returns

string

JSON encode a string value by escaping characters as necessary

_encodeString($string) : string

Parameters

$string

Returns

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

_encodeValue(mixed $value) : string

Parameters

$value

mixed

The value to be encoded

Returns

stringEncoded value

Convert a string from one UTF-8 char to one UTF-16 char.

_utf82utf16(string $utf8) : string
Static

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

link http://solarphp.com

Parameters

$utf8

string

UTF-8 character

Returns

stringUTF-16 character

Determine if an object has been serialized already

_wasVisited(mixed $value) : boolean

Parameters

$value

mixed

Returns

boolean

Encode the constants associated with the ReflectionClass parameter. The encoding format is based on the class2 format

_encodeConstants(\ReflectionClass $cls) : string
Static

Parameters

$cls

\ReflectionClass

Returns

stringEncoded constant block in class2 format

Encode the public methods of the ReflectionClass in the class2 format

_encodeMethods(\ReflectionClass $cls) : string
Static

Parameters

$cls

\ReflectionClass

Returns

stringEncoded method fragment

Encode the public properties of the ReflectionClass in the class2 format.

_encodeVariables(\ReflectionClass $cls) : string
Static

Parameters

$cls

\ReflectionClass

Returns

stringEncode properties list

 Properties

 

Whether or not to check for possible cycling

$_cycleCheck : boolean

Default

 

Additional options used during encoding

$_options : array

Default

array()
 

Array of visited objects; used to prevent cycling.

$_visited : array

Default

array()