Implement ObjectCastInterface::__cast() dispatching on CastObjectHook::getCastType() (ReflectionValue::IS_* constants):
(array) $matrix → toArray()
(string) $matrix → pretty-printed rows
(bool) $matrix → true (a valid matrix is never empty by construction)
Unsupported cast types should fall through to $hook->proceed() so default engine behavior is preserved. The handler runs across the FFI boundary, so it must not throw (PHP 8.4 turns throws from FFI callbacks into fatal errors) — keep it allocation-only.
Implement
ObjectCastInterface::__cast()dispatching onCastObjectHook::getCastType()(ReflectionValue::IS_*constants):(array) $matrix→toArray()(string) $matrix→ pretty-printed rows(bool) $matrix→true(a valid matrix is never empty by construction)Unsupported cast types should fall through to
$hook->proceed()so default engine behavior is preserved. The handler runs across the FFI boundary, so it must not throw (PHP 8.4 turns throws from FFI callbacks into fatal errors) — keep it allocation-only.