Last active
May 11, 2023 17:46
-
-
Save DaveLiddament/56ad3f3cb054ff448ad1e8858a83855c to your computer and use it in GitHub Desktop.
Example of usage of NamespaceVisbility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Foo { | |
class Telephone | |
{ | |
#[NamespaceVisibility] | |
public function ring(): void | |
{ | |
} | |
} | |
class Ringer | |
{ | |
public function ring(Telephone $telephone): Person | |
{ | |
$telephone->ring(); // ✅ OK calling Telephone::ring() from same namespace | |
} | |
} | |
} | |
namespace Foo\SubNamespace { | |
use Foo\Telephone; | |
class SubNamespaceRinger | |
{ | |
public function ring(Telephone $telephone): Person | |
{ | |
$telephone->ring(); // ✅ OK calling Telephone::ring() from sub namespace | |
} | |
} | |
} | |
namespace Bar { | |
use Foo\Telephone; | |
class DifferentNamespaceRinger | |
{ | |
public function ring(Telephone $telephone): Person | |
{ | |
$telephone->ring(); // ❌ ERROR calling Telephone::ring() from different namespace | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment