Index

MMO\core\objects

MMO\core\objects · 18 symbols · generated 5 Oct 2026

function

compare

objects.php:447
Type-aware comparison of two arbitrary values, handling cases plain `<=>`/`==` don't get right on their own (iComparable objects, BackedEnum vs its raw backing value, DateTimeInterface by timestamp, arrays by recursively-[`isSame()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/objects.md#issame) elements). The return value has two different shapes depending on how the values were compared, which is why [`isEqual()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/objects.md#isequal) and [`isSame()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/objects.md#issame) below check it differently -- see their own docblocks for exactly what each captures: - `true`: the values are STRICTLY equal (`$a === $b`, or an iComparable reported so).function compare(mixed $a, mixed $b): int|bool
Namespace
MMO\core\objects
- `false`: the values are unequal in a comparison that has no notion of ordering (e.g. two unrelated objects). - `int`: an ordering result, spaceship-operator style (negative = $a < $b, 0 = loosely equal, positive = $a > $b).
$amixed
$bmixed
returnsint | bool
compare(1, 1); // true (===) compare(1, 1.0); // 0 (== but not ===, ordering-comparable) compare(1, 2); // -1 compare((object)['a'=>1], (object)['a'=>2]); // false (unequal, not orderable)
Call graph
function

connect

objects.php:372
Auto-wire an object's (or, for a static/string $obj, a class's static) methods to events, by reading their #[MMO\core\attributes\Listen(EventClass::class)] attributes and registering each as a listener on that event class. A method already connected (same object+method already listening) is left alone rather than duplicated.function connect(object|string $obj, ?string $classFilter = null): void
Namespace
MMO\core\objects
If a #[Listen] targets a class that isn't currently loaded (e.g. an optional/not-installed package), that one attribute is skipped (with a notice logged, if $obj is an iLogEmitter) instead of failing the whole call.
$objobject | stringthe instance (or classname, for static listeners) to connect
$classFilter = nullnull | stringonly connect #[Listen] attributes targeting this class or a descendant of it
returnsvoid
throws
class MyController { #[Listen(Route::class)] public function onRoute(Route $r): void {...} } connect(new MyController()); //onRoute() now runs on every dispatched Route event
Call graph
function

disconnect

objects.php:407

Undo a previous connect(): remove an object's (or class's) #[Listen]-declared methods from the events they were registered on.

function disconnect(object|string $obj, ?string $classFilter = null): void
Namespace
MMO\core\objects
NOTE: like connect(), a #[Listen] targeting a class that isn't currently loaded is skipped (with a notice logged, if $obj is an iLogEmitter) rather than fatally erroring on `$class::RemoveListener(...)` -- this mirrors connect()'s own guard, since an object connected while a class was unavailable must also be safely disconnectable once it becomes unavailable again (e.g. an optional package that got unloaded in between).
$objobject | stringthe instance (or classname) to disconnect
$classFilter = nullnull | stringonly disconnect #[Listen] attributes targeting this class or a descendant of it
returnsvoid
throws
disconnect($myController); //stop myController's #[Listen]-attributed methods from firing
Call graph
function

enumFrom

objects.php:51

Same as tryEnumFrom(), but throws instead of returning null when nothing matches.

function enumFrom(string $enum, string|int $value): UnitEnum
Namespace
MMO\core\objects
$enumstringthe enum's classname
$valuestring | intthe backing value or the case name
returnsUnitEnum
throwsif no case matches $value
enumFrom(Status::class, 'active'); // Status::Active, or throws eNotFound
Call graph

Uses (1)

function

greaterThan

objects.php:525

Tells if $a orders after $b (per compare()'s ordering result).

function greaterThan(mixed $a, mixed $b, bool $orEqual = false): bool
Namespace
MMO\core\objects
$amixed
$bmixed
$orEqual = falseboolif true, also return true when $a and $b are equal (strict or loose)
returnsbool
greaterThan(2, 1); // true greaterThan(1, 1); // false greaterThan(1, 1, true); // true
Call graph

Uses (1)

function

isEqual

objects.php:492

Tells if two values are STRICTLY equal, per compare() (i.e. compare() returned true, not just 0).

function isEqual(mixed $a, mixed $b): bool
Namespace
MMO\core\objects
NOTE: for two values that are only loosely equal (`==` but not `===`, e.g. `int(1)` and `float(1.0)`, or two distinct-but-`==`-equal objects), compare() returns `0` rather than `true`, so isEqual() reports false for those. If you want "equal in either sense", use [`isSame()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/objects.md#issame) instead -- which is what the rest of this framework (change-tracking, filters, ...) actually uses.
$amixed
$bmixed
returnsbool
isEqual(1, 1); // true isEqual(1, 1.0); // false (== but not ===)
Call graph

Uses (1)

function

isSame

objects.php:509

Tells if two values are equal, in either sense compare() can report equality (strict true, or the ordering-comparison tie value 0). This is the equality check used throughout the framework for detecting whether a property's value actually changed (tArrayProperties), for entity/array property matching, and for the Filter::Equal/Filter::Diff query filters.

function isSame(mixed $a, mixed $b): bool
Namespace
MMO\core\objects
$amixed
$bmixed
returnsbool
isSame(1, 1); // true isSame(1, 1.0); // true (unlike isEqual()) isSame(['a' => 1], ['a' => 1]); // true (recursive)
Call graph
function

isSerialized

objects.php:90

Tells if an array (recursively) contains at least one serialized-object marker (a ['$' => ...] entry, as produced by serialize()), meaning it needs unserialize() to be turned back into real objects.

function isSerialized(array $data): bool
Namespace
MMO\core\objects
$dataarray
returnsbool
isSerialized(['a' => 1, 'b' => ['$' => MyClass::class, 'x' => 1]]); // true isSerialized(['a' => 1, 'b' => ['x' => 1]]); // false
Call graph
function

lesserThan

objects.php:538

Tells if $a orders before $b (per compare()'s ordering result).

function lesserThan(mixed $a, mixed $b, bool $orEqual = false): bool
Namespace
MMO\core\objects
$amixed
$bmixed
$orEqual = falseboolif true, also return true when $a and $b are equal (strict or loose)
returnsbool
lesserThan(1, 2); // true
Call graph

Uses (1)

function

serialize

objects.php:118

Serialize an object (or an array possibly containing objects) into a plain, JSON-safe nested array that

function serialize(object|array $value, string $path = '', ?WeakMap $hashes = null): array
Namespace
MMO\core\objects
See
unserialize() can later turn back into live objects. An object is serialized as ['$' => <factory>, ...properties], where <factory> is either a classname (its properties are then reflected back in on unserialize -- serializeProperties/unserializeProperties), or a callable (a plain function reference for special cases like enums/DateTime -- its args are the array's remaining numeric entries). When the same object is encountered a second time within one call (a cycle, or simply shared by reference), it is serialized as a back-reference ['$' => '#path/to/the/first/occurrence'] instead of being duplicated/recursing infinitely. - Use the attribute \MMO\core\attributes\Serialize on a property to alter how (or whether) it is serialized. - Implement \MMO\core\interfaces\iSerializable on a class to take full control of its serialization.
$valueobject | array
$path = ''stringthe current path in the overall structure being serialized (used to build back-references)
$hashes = nullnull | WeakMapinternal: tracks objects already serialized in this call, to detect cycles/sharing
returnsarray
serialize(['a' => 1, 'b' => new DateTime('2024-01-01')]); // ['a' => 1, 'b' => ['$' => 'MMO\core\objects\unserializeDateTime', '2024-01-01T00:00:00.000+00:00']]
Call graph
function

serializeProperties

objects.php:159

Reflect over an object's properties and serialize them into a plain array (the default serialization strategy used by serialize() for objects that don't implement iSerializable themselves).

function serializeProperties(object $obj, callable $serializer, string $path = ''): array
Namespace
MMO\core\objects
Every property is included unless its #[Serialize] attribute says otherwise (a property can rename itself to a getter's return value, or opt out of serialization entirely -- [`Serialize`](https://mcp.mmoframework.fr/documentation/mmo.core/php/attributes/Serialize.md#serialize)).
$objobjectthe object to serialize
$serializercallablethe function to serialize inner objects|arrays: function(array|object $value, string $path): mixed
$path = ''stringthe current path of the serialization
returnsarray['$' => get_class($obj), ...serializedProperties]
class Point { public function __construct(public int $x, public int $y) {} } serializeProperties(new Point(1, 2), fn($v, $p) => $v); // ['$' => 'Point', 'x' => 1, 'y' => 2]
Call graph
function

tryEnumFrom

objects.php:30

Get an enum case from its backing value (for a BackedEnum) or its case name (for any enum), without throwing.

function tryEnumFrom(string $enum, string|int $value): ?UnitEnum
Namespace
MMO\core\objects
$enumstringthe enum's classname
$valuestring | intthe backing value (e.g. 1, 'active') or the case name (e.g. 'ACTIVE')
returnsnull | UnitEnumnull if no case matches
enum Status: string { case Active = 'active'; case Closed = 'closed'; } tryEnumFrom(Status::class, 'active'); // Status::Active (matched by backing value) tryEnumFrom(Status::class, 'Active'); // Status::Active (matched by case name) tryEnumFrom(Status::class, 'unknown'); // null
Call graph
function

uniqueClassID

objects.php:69

Get a small, stable, per-class-sequential id for an object (1, 2, 3, ... within each class), for the duration of the current request only. The same object always returns the same id (tracked via a WeakMap, so it doesn't keep the object alive). Mainly used by the debug dumper (\MMO\dump()/idump()) to give the developer a short, human-readable label to tell apart several instances of the same class in a dump.

function uniqueClassID(object $value): int
Namespace
MMO\core\objects
$valueobject
returnsint
$a = new MyClass(); $b = new MyClass(); uniqueClassID($a); // 1 uniqueClassID($b); // 2 uniqueClassID($a); // 1 (same object, same id)
Call graph
function

unserialize

objects.php:204

Turn data produced by serialize() back into live objects/arrays.

function unserialize( array $data, string $path = '', MMO\core\helpers\Container|array &$instances = [] ): mixed
Namespace
MMO\core\objects
- A plain array (no `$` key) is walked recursively, unserializing any nested serialized array in it. - `['$' => '#path']` resolves a back-reference: if $instances is a plain array, it's looked up by that path key (the same $instances array must have been threaded through the whole recursive call, so earlier objects are still in it); if $instances is a Container (e.g. the global Configuration), '#path' is resolved as a path into it instead -- and if that path also happens to be an already-loaded classname, it resolves to that class's *shared instance* rather than a plain config value (this is what lets `['$' => '#' . SomeService::class]` mean "the shared SomeService instance"). - `['$' => callable, ...args]` calls the callable with the (recursively unserialized) remaining args. - `['$' => 'SomeClass', ...properties]` creates a `SomeClass` instance *without* calling its constructor, restores its properties ([`unserializeProperties()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/objects.md#unserializeproperties), or SomeClass::unserialize() if it implements iSerializable), reconnects its `#[Listen]` attributes ([`connect()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/objects.md#connect)), then calls `__wakeup()` if it has one.
$dataarray
$path = ''stringthe current path in the overall structure (used to resolve/build '#' back-references)
$instances = []Container | array
returnsmixed
throws
unserialize(['$' => 'MMO\core\objects\unserializeDateTime', '2024-01-01T00:00:00.000+00:00']); //a DateTime unserialize(['$' => 'Point', 'x' => 1, 'y' => 2]); //a `new Point` with x/y set, constructor NOT called
Call graph
function

unserializeDateTime

objects.php:341

Factory used by unserialize() to restore a DateTime serialized by serialize().

function unserializeDateTime(string $RFCDate): DateTime
Namespace
MMO\core\objects
$RFCDatestringa date formatted per \DateTimeInterface::RFC3339_EXTENDED
returnsDateTime
unserializeDateTime('2024-01-01T00:00:00.000+00:00');
function

unserializeDateTimeImmutable

objects.php:351

Same as unserializeDateTime(), but returns a DateTimeImmutable.

function unserializeDateTimeImmutable(string $RFCDate): DateTimeImmutable
Namespace
MMO\core\objects
$RFCDatestringa date formatted per \DateTimeInterface::RFC3339_EXTENDED
returnsDateTimeImmutable
unserializeDateTimeImmutable('2024-01-01T00:00:00.000+00:00');
function

unserializeEnum

objects.php:328

Factory used by unserialize() to restore an enum case serialized by serialize() (['$' => ...unserializeEnum, $class, $case->name]).

function unserializeEnum(string $class, string $name): UnitEnum
Namespace
MMO\core\objects
$classstringthe enum's classname
$namestringthe case's name (NOT its backing value -- tryEnumFrom for that)
returnsUnitEnum
unserializeEnum(Status::class, 'Active'); // Status::Active
function

unserializeProperties

objects.php:275

Restore an object's properties from serialized data, via reflection (bypassing setters).

function unserializeProperties( object $obj, array $data, string $path = '', MMO\core\helpers\Container|array &$instances = [], ?ReflectionClass $ref = null ): object
Namespace
MMO\core\objects
Properties are set in the order given by their #[Serialize] attribute's `order` (default 0), which lets a class ensure some properties are restored before others that might depend on them (e.g. paths before routes). A property whose #[Serialize] declares an `unserialize` method/callable has that called with the raw value instead of a plain reflection `setValue()` -- letting a property do custom logic (e.g. `setStream()`) rather than just being overwritten. A readonly property inherited from a parent class is set through that parent class's own ReflectionProperty, since PHP only allows writing a readonly property from its declaring scope.
$objobjectthe (already-created, but not yet populated) object to restore properties on
$dataarraythe serialized properties (without the '$' key)
$path = ''stringthe current path in the overall structure (passed down to nested unserialize() calls)
$instances = []Container | array
$ref = nullnull | ReflectionClassreflection of $obj's class. Computed automatically if not given.
returnsobject$obj, for convenience
throws
unserializeProperties(new Point(0, 0), ['x' => 1, 'y' => 2]); //Point{x: 1, y: 2}
Call graph