Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#2043 from Ocramius/per…
Browse files Browse the repository at this point in the history
…formance/register-callback-weak-ref-caching

Smaller performance optimization by caching availability of WeakRef pecl extension
  • Loading branch information
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/CallbackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class CallbackHandler
*/
protected static $isPhp54;

/**
* Is pecl/weakref extension installed?
* @var boolean
*/
protected static $hasWeakRefExtension;

/**
* Constructor
*
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 1ab2258

Please sign in to comment.