Transition to spl_object_id()

This commit is contained in:
Dylan K. Taylor
2019-01-26 15:06:38 +00:00
parent 1e708db26c
commit d378371cc8
15 changed files with 59 additions and 59 deletions

View File

@ -27,7 +27,7 @@ use pocketmine\utils\Utils;
use function array_keys;
use function assert;
use function count;
use function spl_object_hash;
use function spl_object_id;
use function time;
use const PHP_INT_MAX;
use const PTHREADS_INHERIT_CONSTANTS;
@ -97,7 +97,7 @@ class AsyncPool{
*/
public function addWorkerStartHook(\Closure $hook) : void{
Utils::validateCallableSignature(function(int $worker) : void{}, $hook);
$this->workerStartHooks[spl_object_hash($hook)] = $hook;
$this->workerStartHooks[spl_object_id($hook)] = $hook;
foreach($this->workers as $i => $worker){
$hook($i);
}
@ -109,7 +109,7 @@ class AsyncPool{
* @param \Closure $hook
*/
public function removeWorkerStartHook(\Closure $hook) : void{
unset($this->workerStartHooks[spl_object_hash($hook)]);
unset($this->workerStartHooks[spl_object_id($hook)]);
}
/**

View File

@ -25,7 +25,7 @@ namespace pocketmine\scheduler;
use function is_scalar;
use function serialize;
use function spl_object_hash;
use function spl_object_id;
use function unserialize;
/**
@ -256,7 +256,7 @@ abstract class AsyncTask extends \Threaded{
*/
self::$threadLocalStorage = new \ArrayObject();
}
self::$threadLocalStorage[spl_object_hash($this)] = $complexData;
self::$threadLocalStorage[spl_object_id($this)] = $complexData;
}
/**
@ -270,16 +270,16 @@ abstract class AsyncTask extends \Threaded{
* @throws \InvalidArgumentException if no data were stored by this AsyncTask instance.
*/
protected function fetchLocal(){
if(self::$threadLocalStorage === null or !isset(self::$threadLocalStorage[spl_object_hash($this)])){
if(self::$threadLocalStorage === null or !isset(self::$threadLocalStorage[spl_object_id($this)])){
throw new \InvalidArgumentException("No matching thread-local data found on this thread");
}
return self::$threadLocalStorage[spl_object_hash($this)];
return self::$threadLocalStorage[spl_object_id($this)];
}
final public function __destruct(){
$this->reallyDestruct();
if(self::$threadLocalStorage !== null and isset(self::$threadLocalStorage[$h = spl_object_hash($this)])){
if(self::$threadLocalStorage !== null and isset(self::$threadLocalStorage[$h = spl_object_id($this)])){
unset(self::$threadLocalStorage[$h]);
if(self::$threadLocalStorage->count() === 0){
self::$threadLocalStorage = null;