diff --git a/src/CallbackHandler.php b/src/CallbackHandler.php index ca12f9244..cdc50511f 100644 --- a/src/CallbackHandler.php +++ b/src/CallbackHandler.php @@ -43,6 +43,12 @@ class CallbackHandler */ protected static $isPhp54; + /** + * Is pecl/weakref extension installed? + * @var boolean + */ + protected static $hasWeakRefExtension; + /** * Constructor * @@ -76,8 +82,12 @@ protected function registerCallback($callback) throw new Exception\InvalidCallbackException('Invalid callback provided; not callable'); } + if (null === self::$hasWeakRefExtension) { + self::$hasWeakRefExtension = class_exists('WeakRef'); + } + // If pecl/weakref is not installed, simply store the callback and return - if (!class_exists('WeakRef')) { + if (!self::$hasWeakRefExtension) { $this->callback = $callback; return; }