CooperAtom
in package
implements
Stringable, JsonSerializable
A CASC atom (CASC.md §6.4) -- `level = info`, `level = :info`.
PHP has no atom type, and a plain string would erase the difference
between level = info and level = "info" that the format itself
draws. Instances are interned: CooperAtom::of('info') always returns
the same object, so $config['level'] === CooperAtom::of('info')
works the way an Elixir config.level == :info does.
:true, :false, and :nil are not atoms but the values true,
false, and null (CASC.md §6.4 as amended): on the Elixir
original's runtime those atoms are the values, and a document must
mean the same thing everywhere. :inf is an ordinary atom.
Interning only holds within one process; an atom that went through
serialize()/unserialize() is a distinct object, so compare with
equals() (or ->name) if a value may have been serialized.
Table of Contents
Interfaces
- Stringable
- JsonSerializable
Properties
- $name : string
- $interned : array<string, CooperAtom>
Methods
- __toString() : string
- The atom's name, without a leading `:` -- the same text an interpolated `"@{level}"` produces.
- equals() : bool
- Whether `$other` is an atom with the same name.
- jsonSerialize() : string
- Encodes as the atom's name.
- of() : self
- Returns the (interned) atom named `$name`.
- __construct() : mixed
Properties
$name read-only
public
string
$name
$interned
private
static array<string, CooperAtom>
$interned
= []
Methods
__toString()
The atom's name, without a leading `:` -- the same text an interpolated `"@{level}"` produces.
public
__toString() : string
Return values
string —the atom's name
equals()
Whether `$other` is an atom with the same name.
public
equals(mixed $other) : bool
Parameters
- $other : mixed
-
the value to compare against
Return values
bool —true for an atom of the same name
jsonSerialize()
Encodes as the atom's name.
public
jsonSerialize() : string
Return values
string —the atom's name
of()
Returns the (interned) atom named `$name`.
public
static of(string $name) : self
Parameters
- $name : string
-
the atom's name, without any leading
:
Return values
self —the one instance for that name
__construct()
private
__construct(string $name) : mixed
Parameters
- $name : string