Skip to content

Instantly share code, notes, and snippets.

@DaveLiddament
Last active May 11, 2023 17:46
Show Gist options
  • Save DaveLiddament/56ad3f3cb054ff448ad1e8858a83855c to your computer and use it in GitHub Desktop.
Save DaveLiddament/56ad3f3cb054ff448ad1e8858a83855c to your computer and use it in GitHub Desktop.
Example of usage of NamespaceVisbility
<?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