Skip to content

Instantly share code, notes, and snippets.

@azjezz
Last active April 22, 2021 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azjezz/db734fd148f84202d19de8479dea2710 to your computer and use it in GitHub Desktop.
Save azjezz/db734fd148f84202d19de8479dea2710 to your computer and use it in GitHub Desktop.
<?php
#[Sealed(ExtendedUserInterface::class, User::class)]
interface UserInterface {}
// ok
interface ExtendedUserInterface extends UserInterface {}
// ok
class User implements UserInterface {}
// error: cannot extend sealed interface UserInterface
interface MyUserInterface extends UserInterface {}
// error cannot implement sealed interface UserInterface
interface Myuser implements UserInterface {}
#[Sealed(Bar::class)]
class Foo {}
// ok
class Bar extends Foo {}
// error: Cannot extend sealed class Foo.
class Baz extends Foo {}
// ok
class Qux extends Bar {}
<?php
#[Sealed(Exception::class, Error::class)]
interface Throwable {}
#[Sealed(Partial::class)]
interface Closure {}
<?php
interface Throwable for Exception, Error {}
interface Closure for Partial {}
<?php
interface UserInterface for User, ExtendedUserInterface {}
// ok
interface ExtendedUserInterface extends UserInterface {}
// ok
class User implements UserInterface {}
// error: cannot extend sealed interface UserInterface
interface MyUserInterface extends UserInterface {}
// error cannot implement sealed interface UserInterface
interface Myuser implements UserInterface {}
class Foo for Bar {}
// ok
class Bar extends Foo {}
// error: Cannot extend sealed class Foo.
class Baz extends Foo {}
// ok
class Qux extends Bar {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment