Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Snapshot.php

function Snapshot::canBeSerialized

2 calls to Snapshot::canBeSerialized()
Snapshot::snapshotGlobals in vendor/sebastian/global-state/src/Snapshot.php
Snapshot::snapshotStaticProperties in vendor/sebastian/global-state/src/Snapshot.php

File

vendor/sebastian/global-state/src/Snapshot.php, line 279

Class

Snapshot
A snapshot of global state.

Namespace

SebastianBergmann\GlobalState

Code

private function canBeSerialized(mixed $variable) : bool {
    if (is_scalar($variable) || $variable === null) {
        return true;
    }
    if (is_resource($variable)) {
        return false;
    }
    foreach ($this->enumerateObjectsAndResources($variable) as $value) {
        if (is_resource($value)) {
            return false;
        }
        if (is_object($value)) {
            $class = new ReflectionClass($value);
            if ($class->isAnonymous()) {
                return false;
            }
            try {
                @serialize($value);
            } catch (Throwable $t) {
                return false;
            }
        }
    }
    return true;
}
RSS feed
Powered by Drupal