Skip to content

Commit

Permalink
Merge pull request guzzle#105 from jimcottrell/master
Browse files Browse the repository at this point in the history
Add explicit object checks before calling method_exists()
  • Loading branch information
Tobion authored Feb 12, 2020
2 parents 4771454 + 3976c7d commit 6379353
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FulfilledPromise implements PromiseInterface

public function __construct($value)
{
if (method_exists($value, 'then')) {
if (is_object($value) && method_exists($value, 'then')) {
throw new \InvalidArgumentException(
'You cannot create a FulfilledPromise with a promise.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private function settle($state, $value)

// If the value was not a settled promise or a thenable, then resolve
// it in the task queue using the correct ID.
if (!method_exists($value, 'then')) {
if (!is_object($value) || !method_exists($value, 'then')) {
$id = $state === self::FULFILLED ? 1 : 2;
// It's a success, so resolve the handlers in the queue.
queue()->add(static function () use ($id, $value, $handlers) {
Expand Down
2 changes: 1 addition & 1 deletion src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RejectedPromise implements PromiseInterface

public function __construct($reason)
{
if (method_exists($reason, 'then')) {
if (is_object($reason) && method_exists($reason, 'then')) {
throw new \InvalidArgumentException(
'You cannot create a RejectedPromise with a promise.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function promise_for($value)
}

// Return a Guzzle promise that shadows the given promise.
if (method_exists($value, 'then')) {
if (is_object($value) && method_exists($value, 'then')) {
$wfn = method_exists($value, 'wait') ? [$value, 'wait'] : null;
$cfn = method_exists($value, 'cancel') ? [$value, 'cancel'] : null;
$promise = new Promise($wfn, $cfn);
Expand Down

0 comments on commit 6379353

Please sign in to comment.