Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nullable parameter types explicit #34

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.3.1 - unreleased

- Made nullable parameter types explicit (PHP 8.4 compatibility)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this going to be a BC break of PHP 8.4, or only become deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP 8.4 triggers a E_DEPRECATED error when it loads a file with this kind of parameter type declaration.


## 1.3.0 - 2024-01-04

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct($result)
$this->result = $result;
}

public function then(callable $onFulfilled = null, callable $onRejected = null)
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
{
if (null === $onFulfilled) {
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface Promise
*
* @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected)
*/
public function then(callable $onFulfilled = null, callable $onRejected = null);
public function then(?callable $onFulfilled = null, ?callable $onRejected = null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik this is a BC break for anything implementing the promise, right?

if it is, we should bump the major version number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the code is 100% equivalent. This has always been a nullable type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example where I examine the type with reflection:

https://3v4l.org/EQimk

One parameter is declared callable, the other ?callable. As you can see in the output, both parameters look the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. i also added a class that implements the interface and changes ?
at least up to 8.3 this is indeed equivalent.

thanks for the clarification, then we can savely merge this.


/**
* Returns the state of the promise, one of PENDING, FULFILLED or REJECTED.
Expand Down
2 changes: 1 addition & 1 deletion src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(\Throwable $exception)
$this->exception = $exception;
}

public function then(callable $onFulfilled = null, callable $onRejected = null)
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
{
if (null === $onRejected) {
return $this;
Expand Down
Loading