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

Check for #[Override] annotation #173

Merged
merged 19 commits into from
Jul 16, 2023
Merged

Check for #[Override] annotation #173

merged 19 commits into from
Jul 16, 2023

Conversation

thekid
Copy link
Member

@thekid thekid commented Jul 15, 2023

Implements #149, see https://wiki.php.net/rfc/marking_overriden_methods. In comparison with #172, these checks are always performed during compilation (even for PHP 8.3+, as there is no measurable performance impact in doing so and we prevent uncatchable fatal errors).

In a nutshell

This first example works without any problem (as would simply omitting this annotation):

use Override;
use lang\Throwable;

class CannotConnect extends Throwable {

  #[Override]
  public function compoundMessage() { }
}

The following all raise compile errors:

use Override;
use lang\{Runnable, Throwable};

// No parent class
class CannotConnect {

  #[Override]
  public function compoundMessage() { }
}

// Parent class doesn't have such a method
class CannotConnect extends Throwable {

  #[Override]
  public function composeMessage() { }
}

// None of the implemented interfaces have such a method
class RunOnce implements Runnable {

  #[Override]
  public function doRun() { }
}

Performance impact

👉 Not measurable

Before:

$ xp test src/test/php/
# ...
Test cases:  945 succeeded, 3 skipped
Memory used: 11531.30 kB (11585.42 kB peak)
Time taken:  0.227 seconds (0.636 seconds overall)

After:

$ xp test src/test/php/
# ...
Test cases:  955 succeeded, 3 skipped
Memory used: 11649.20 kB (11703.33 kB peak)
Time taken:  0.233 seconds (0.632 seconds overall)

@thekid thekid added the php label Jul 15, 2023
@thekid thekid merged commit 3d6a5a0 into master Jul 16, 2023
@thekid thekid deleted the feature/override-trait branch July 16, 2023 12:46
@thekid thekid mentioned this pull request Jul 16, 2023
2 tasks
@thekid
Copy link
Member Author

thekid commented Jul 16, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant