1082. Class

1082.1. Zend\Json\Encoder

Encode PHP constructs to JSON

1082.1.1. Methods

1082.1.1.1. __construct

__construct()

Constructor

Parameters:
  • bool – Whether or not to check for recursion when encoding
  • array – Additional options used during encoding
Return type:

Encoder

1082.1.1.2. encode

encode()

Use the JSON encoding scheme for the value specified

Parameters:
  • mixed – The value to be encoded
  • bool – Whether or not to check for possible object recursion when encoding
  • array – Additional options used during encoding
Return type:

string The encoded value

1082.1.1.3. _encodeValue

_encodeValue()

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()})
Parameters:$value – The value to be encoded
Return type:string Encoded value

1082.1.1.4. _encodeObject

_encodeObject()

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.

Parameters:$value
Return type:string
Throws :RecursionException If recursive checks are enabled and the object has been serialized previously

1082.1.1.5. _wasVisited

_wasVisited()

Determine if an object has been serialized already

Parameters:mixed
Return type:bool

1082.1.1.6. _encodeArray

_encodeArray()

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.

Parameters:$array
Return type:string

1082.1.1.7. _encodeDatum

_encodeDatum()

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.

Parameters:mixed
Return type:string

1082.1.1.8. _encodeString

_encodeString()

JSON encode a string value by escaping characters as necessary

Parameters:string
Return type:string

1082.1.1.9. _encodeConstants

_encodeConstants()

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

Parameters:ReflectionClass
Return type:string Encoded constant block in class2 format

1082.1.1.10. _encodeMethods

_encodeMethods()

Encode the public methods of the ReflectionClass in the class2 format

Parameters:ReflectionClass
Return type:string Encoded method fragment

1082.1.1.11. _encodeVariables

_encodeVariables()

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

Parameters:ReflectionClass
Return type:string Encode properties list

1082.1.1.12. encodeClass

encodeClass()

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

Parameters:$className – The name of the class, the class must be
instantiable using a null constructor
param $package:Optional package name appended to JavaScript

proxy class name

rtype:string The class2 (JavaScript) encoding of the class
throws:InvalidArgumentException

1082.1.1.13. encodeClasses

encodeClasses()

Encode several classes at once

Returns JSON encoded classes, using {@link encodeClass()}.

Parameters:
  • array
  • string
Return type:

string

1082.1.1.14. encodeUnicodeString

encodeUnicodeString()

Encode Unicode Characters to u0000 ASCII syntax.

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

Parameters:string
Return type:string

1082.1.1.15. _utf82utf16

_utf82utf16()

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 multibyte string extension.

This method is from the Solar Framework by Paul M. Jones

Parameters:string – UTF-8 character
Return type:string UTF-16 character