From 604023bd2ae6e0e6b80fc42cb3f27462ed378f0b Mon Sep 17 00:00:00 2001 From: Brent Kelly Date: Sun, 30 Aug 2020 11:05:59 +1200 Subject: [PATCH] Use full function namespaces to avoid clashes with serialization `Promise.php` contains function calls that expect the current namespace. However if you serialize & then later unserialize a Promise, this namespace is lost, and the function calls clash with other defined global functions. E.g. if using Laravel, you serialize a `\React\Promise\Promise` instance, and then later unserialize & attempt to resolve it - the call to `resolve` on line 232 clashes with Laravel's global `resolve` function - causing it to throw an exception. By using the full namespace on the function call this eliminates this possible problem. Also makes the code an easier read IMO making it obvious that these are namespaced functions. --- src/Promise.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Promise.php b/src/Promise.php index a4765e08..5f738507 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -84,11 +84,11 @@ public function otherwise(callable $onRejected): PromiseInterface public function always(callable $onFulfilledOrRejected): PromiseInterface { return $this->then(static function ($value) use ($onFulfilledOrRejected) { - return resolve($onFulfilledOrRejected())->then(function () use ($value) { + return \React\Promise\resolve($onFulfilledOrRejected())->then(function () use ($value) { return $value; }); }, static function ($reason) use ($onFulfilledOrRejected) { - return resolve($onFulfilledOrRejected())->then(function () use ($reason) { + return \React\Promise\resolve($onFulfilledOrRejected())->then(function () use ($reason) { return new RejectedPromise($reason); }); }); @@ -146,7 +146,7 @@ private function reject(\Throwable $reason): void return; } - $this->settle(reject($reason)); + $this->settle(\React\Promise\reject($reason)); } private function settle(PromiseInterface $result): void @@ -223,7 +223,7 @@ private function call(callable $cb): void $callback( static function ($value = null) use (&$target) { if ($target !== null) { - $target->settle(resolve($value)); + $target->settle(\React\Promise\resolve($value)); $target = null; } },