3 ION supports many of PHP's data types:
7 Additonally to the plain and simple `NULL`, ION can attach a type to `NULL` values.
12 $writer = new ion\Writer\Stream\Writer(STDOUT);
14 $writer->writeTypedNull(ion\Type::Int);
15 $writer->writeTypedNull(ion\Type::String);
29 The bool type does not need a lot of explanation:
34 $writer->writeBool(true);
35 $writer->writeBool(false);
48 The int type comprises signed integers of arbitrary size.
53 $writer->writeInt(123);
54 $writer->writeInt("12345678901234567890");
65 In ION-Text, underscores are allowed to separate digits:
70 $reader = new ion\Reader\Buffer\Reader("-123_456_789");
72 var_dump($reader->getType());
73 var_dump($reader->readInt());
83 Hexadecimal as well as binary notation are supported, too:
88 $reader = new ion\Reader\Buffer\Reader("0xdead_beef");
90 var_dump($reader->readInt());
96 $reader = new ion\Reader\Buffer\Reader("0b10000100_11001001");
98 var_dump($reader->readInt());
109 Ion supports both binary and lossless decimal encodings of real numbers as, respectively, types `float` and `decimal`. In the text format, `float` values are denoted much like the decimal formats in C or Java; `decimal` values use `d` instead of `e` to start the exponent.
111 Reals without an exponent are treated as decimal. As with JSON, extra leading zeros are not allowed. Digits may be separated with an underscore.
118 var_dump(ion\serialize(0.123));
121 string(25) "0.12299999999999999822e+0"
124 var_dump(ion\unserialize("[0.123e, 123e-3]"));
143 var_dump(ion\serialize(new ion\Decimal("0.123")));
149 var_dump(ion\unserialize("[0.123d0, 123d-3]"));
154 object(ion\Decimal)#8 (2) {
160 object(ion\Decimal)#11 (2) {
173 Ion strings are Unicode character sequences of arbitrary length.
175 In the text format, strings are delimited by double-quotes and follow common backslash-escape conventions (see [official spec](https://amzn.github.io/ion-docs/docs/spec.html#escapess)). The binary format always uses UTF-8 encoding.
194 The text format supports an alternate syntax for “long strings”, including those that break across lines. Sequences bounded by three single-quotes (''') can cross multiple lines and still count as a valid, single string. In addition, any number of adjacent triple-quoted strings are concatenated into a single value.
196 The concatenation happens within the Ion text parser and is neither detectable via the data model nor applicable to the binary format. Note that comments are always treated as whitespace, so concatenation still occurs when a comment falls between two long strings.
201 var_dump(ion\unserialize("
222 Ion defines three container types: structures, lists, and S-expressions. These types are defined recursively and may contain values of any Ion type.
226 Lists are ordered collections of values. The contents of the list are heterogeneous (that is, each element can have a different type). In the text format, lists are bounded by square brackets and elements are separated by commas.
231 ion\serialize([1, "yes", null]);
242 Structures are *unordered* collections of name/value pairs. The names are symbol tokens, and the values are unrestricted. Each name/value pair is called a field.
244 In the text format, structures are wrapped by curly braces, with a colon between each name and value, and a comma between the fields. For the purposes of JSON compatibility, it’s also legal to use strings for field names, but they are converted to symbol tokens by the parser.
252 "obj" => (object)["key" => "value"]
256 {'0':"outlaw",key:"value",obj:o::{key:"value"}}
265 var_dump(ion\unserialize(
266 '{\'0\':"outlaw",key:"value",obj:o::{key:"value"}}'
276 object(stdClass)#10 (1) {
290 * [Special Datatypes](ion/:%20Tutorial/:4.%20Special%20Datatypes)