Last active
October 28, 2016 11:33
-
-
Save brzuchal/5ab8b86a54ca09142b8e9d376823db43 to your computer and use it in GitHub Desktop.
Introducing namespace as struct in PHP
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
=========================================== | |
Namespace: 'PHPTest' | |
=========================================== | |
Array | |
( | |
[name] => PHPTest | |
[internal] => | |
[user-defined] => 1 | |
[parent] => ReflectionNamespace Object | |
( | |
[name] => | |
) | |
[childs] => Array | |
( | |
[PHPTest\SubLevel] => ReflectionNamespace Object | |
( | |
[name] => PHPTest\SubLevel | |
) | |
[PHPTest\SecondSubLevel] => ReflectionNamespace Object | |
( | |
[name] => PHPTest\SecondSubLevel | |
) | |
) | |
[classes] => Array | |
( | |
[PHPTest\MyTestInterface] => ReflectionClass Object | |
( | |
[name] => PHPTest\MyTestInterface | |
) | |
[PHPTest\MyTestClass] => ReflectionClass Object | |
( | |
[name] => PHPTest\MyTestClass | |
) | |
[PHPTest\MyExtendedClass] => ReflectionClass Object | |
( | |
[name] => PHPTest\MyExtendedClass | |
) | |
[PHPTest\SubLevel\TestA] => ReflectionClass Object | |
( | |
[name] => PHPTest\SubLevel\TestA | |
) | |
[PHPTest\SecondSubLevel\TestB] => ReflectionClass Object | |
( | |
[name] => PHPTest\SecondSubLevel\TestB | |
) | |
[PHPTest\SecondSubLevel\TestC] => ReflectionClass Object | |
( | |
[name] => PHPTest\SecondSubLevel\TestC | |
) | |
[PHPTest\SecondSubLevel\TestD] => ReflectionClass Object | |
( | |
[name] => PHPTest\SecondSubLevel\TestD | |
) | |
) | |
) | |
=========================================== | |
Namespace: 'PHPTest\SubLevel' | |
=========================================== | |
Array | |
( | |
[name] => PHPTest\SubLevel | |
[internal] => | |
[user-defined] => 1 | |
[parent] => ReflectionNamespace Object | |
( | |
[name] => PHPTest | |
) | |
[childs] => Array | |
( | |
) | |
[classes] => Array | |
( | |
) | |
) | |
=========================================== | |
Namespace: 'PHPTest\SecondSubLevel' | |
=========================================== | |
Array | |
( | |
[name] => PHPTest\SecondSubLevel | |
[internal] => | |
[user-defined] => 1 | |
[parent] => ReflectionNamespace Object | |
( | |
[name] => PHPTest | |
) | |
[childs] => Array | |
( | |
) | |
[classes] => Array | |
( | |
) | |
) | |
=========================================== | |
Namespace: 'A\B' | |
=========================================== | |
Array | |
( | |
[name] => A\B | |
[internal] => | |
[user-defined] => 1 | |
[parent] => ReflectionNamespace Object | |
( | |
[name] => A | |
) | |
[childs] => Array | |
( | |
) | |
[classes] => Array | |
( | |
) | |
) | |
=========================================== | |
Namespace: 'A' | |
=========================================== | |
Array | |
( | |
[name] => A | |
[internal] => | |
[user-defined] => 1 | |
[parent] => ReflectionNamespace Object | |
( | |
[name] => | |
) | |
[childs] => Array | |
( | |
[A\B] => ReflectionNamespace Object | |
( | |
[name] => A\B | |
) | |
) | |
[classes] => Array | |
( | |
[A\B\FourthLevelClass] => ReflectionClass Object | |
( | |
[name] => A\B\FourthLevelClass | |
) | |
) | |
) | |
=========================================== | |
Namespace: '' | |
=========================================== | |
Array | |
( | |
[name] => | |
[internal] => | |
[user-defined] => 1 | |
[parent] => | |
[childs] => Array | |
( | |
[PHPTest] => ReflectionNamespace Object | |
( | |
[name] => PHPTest | |
) | |
[A] => ReflectionNamespace Object | |
( | |
[name] => A | |
) | |
) | |
[classes] => Array | |
( | |
[stdClass] => ReflectionClass Object | |
( | |
[name] => stdClass | |
) | |
[Traversable] => ReflectionClass Object | |
( | |
[name] => Traversable | |
) | |
[IteratorAggregate] => ReflectionClass Object | |
( | |
[name] => IteratorAggregate | |
) | |
[Iterator] => ReflectionClass Object | |
( | |
[name] => Iterator | |
) | |
[ArrayAccess] => ReflectionClass Object | |
( | |
[name] => ArrayAccess | |
) | |
[Serializable] => ReflectionClass Object | |
( | |
[name] => Serializable | |
) | |
[Throwable] => ReflectionClass Object | |
( | |
[name] => Throwable | |
) | |
[Exception] => ReflectionClass Object | |
( | |
[name] => Exception | |
) | |
[ErrorException] => ReflectionClass Object | |
( | |
[name] => ErrorException | |
) | |
[Error] => ReflectionClass Object | |
( | |
[name] => Error | |
) | |
[ParseError] => ReflectionClass Object | |
( | |
[name] => ParseError | |
) | |
[TypeError] => ReflectionClass Object | |
( | |
[name] => TypeError | |
) | |
[ArgumentCountError] => ReflectionClass Object | |
( | |
[name] => ArgumentCountError | |
) | |
[ArithmeticError] => ReflectionClass Object | |
( | |
[name] => ArithmeticError | |
) | |
[DivisionByZeroError] => ReflectionClass Object | |
( | |
[name] => DivisionByZeroError | |
) | |
[Closure] => ReflectionClass Object | |
( | |
[name] => Closure | |
) | |
[Generator] => ReflectionClass Object | |
( | |
[name] => Generator | |
) | |
[ClosedGeneratorException] => ReflectionClass Object | |
( | |
[name] => ClosedGeneratorException | |
) | |
[DateTimeInterface] => ReflectionClass Object | |
( | |
[name] => DateTimeInterface | |
) | |
[DateTime] => ReflectionClass Object | |
( | |
[name] => DateTime | |
) | |
[DateTimeImmutable] => ReflectionClass Object | |
( | |
[name] => DateTimeImmutable | |
) | |
[DateTimeZone] => ReflectionClass Object | |
( | |
[name] => DateTimeZone | |
) | |
[DateInterval] => ReflectionClass Object | |
( | |
[name] => DateInterval | |
) | |
[DatePeriod] => ReflectionClass Object | |
( | |
[name] => DatePeriod | |
) | |
[ReflectionException] => ReflectionClass Object | |
( | |
[name] => ReflectionException | |
) | |
[Reflection] => ReflectionClass Object | |
( | |
[name] => Reflection | |
) | |
[Reflector] => ReflectionClass Object | |
( | |
[name] => Reflector | |
) | |
[ReflectionFunctionAbstract] => ReflectionClass Object | |
( | |
[name] => ReflectionFunctionAbstract | |
) | |
[ReflectionFunction] => ReflectionClass Object | |
( | |
[name] => ReflectionFunction | |
) | |
[ReflectionGenerator] => ReflectionClass Object | |
( | |
[name] => ReflectionGenerator | |
) | |
[ReflectionParameter] => ReflectionClass Object | |
( | |
[name] => ReflectionParameter | |
) | |
[ReflectionType] => ReflectionClass Object | |
( | |
[name] => ReflectionType | |
) | |
[ReflectionNamedType] => ReflectionClass Object | |
( | |
[name] => ReflectionNamedType | |
) | |
[ReflectionMethod] => ReflectionClass Object | |
( | |
[name] => ReflectionMethod | |
) | |
[ReflectionClass] => ReflectionClass Object | |
( | |
[name] => ReflectionClass | |
) | |
[ReflectionNamespace] => ReflectionClass Object | |
( | |
[name] => ReflectionNamespace | |
) | |
[ReflectionObject] => ReflectionClass Object | |
( | |
[name] => ReflectionObject | |
) | |
[ReflectionProperty] => ReflectionClass Object | |
( | |
[name] => ReflectionProperty | |
) | |
[ReflectionClassConstant] => ReflectionClass Object | |
( | |
[name] => ReflectionClassConstant | |
) | |
[ReflectionExtension] => ReflectionClass Object | |
( | |
[name] => ReflectionExtension | |
) | |
[ReflectionZendExtension] => ReflectionClass Object | |
( | |
[name] => ReflectionZendExtension | |
) | |
[LogicException] => ReflectionClass Object | |
( | |
[name] => LogicException | |
) | |
[BadFunctionCallException] => ReflectionClass Object | |
( | |
[name] => BadFunctionCallException | |
) | |
[BadMethodCallException] => ReflectionClass Object | |
( | |
[name] => BadMethodCallException | |
) | |
[DomainException] => ReflectionClass Object | |
( | |
[name] => DomainException | |
) | |
[InvalidArgumentException] => ReflectionClass Object | |
( | |
[name] => InvalidArgumentException | |
) | |
[LengthException] => ReflectionClass Object | |
( | |
[name] => LengthException | |
) | |
[OutOfRangeException] => ReflectionClass Object | |
( | |
[name] => OutOfRangeException | |
) | |
[RuntimeException] => ReflectionClass Object | |
( | |
[name] => RuntimeException | |
) | |
[OutOfBoundsException] => ReflectionClass Object | |
( | |
[name] => OutOfBoundsException | |
) | |
[OverflowException] => ReflectionClass Object | |
( | |
[name] => OverflowException | |
) | |
[RangeException] => ReflectionClass Object | |
( | |
[name] => RangeException | |
) | |
[UnderflowException] => ReflectionClass Object | |
( | |
[name] => UnderflowException | |
) | |
[UnexpectedValueException] => ReflectionClass Object | |
( | |
[name] => UnexpectedValueException | |
) | |
[RecursiveIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveIterator | |
) | |
[RecursiveIteratorIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveIteratorIterator | |
) | |
[OuterIterator] => ReflectionClass Object | |
( | |
[name] => OuterIterator | |
) | |
[IteratorIterator] => ReflectionClass Object | |
( | |
[name] => IteratorIterator | |
) | |
[FilterIterator] => ReflectionClass Object | |
( | |
[name] => FilterIterator | |
) | |
[RecursiveFilterIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveFilterIterator | |
) | |
[CallbackFilterIterator] => ReflectionClass Object | |
( | |
[name] => CallbackFilterIterator | |
) | |
[RecursiveCallbackFilterIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveCallbackFilterIterator | |
) | |
[ParentIterator] => ReflectionClass Object | |
( | |
[name] => ParentIterator | |
) | |
[Countable] => ReflectionClass Object | |
( | |
[name] => Countable | |
) | |
[SeekableIterator] => ReflectionClass Object | |
( | |
[name] => SeekableIterator | |
) | |
[LimitIterator] => ReflectionClass Object | |
( | |
[name] => LimitIterator | |
) | |
[CachingIterator] => ReflectionClass Object | |
( | |
[name] => CachingIterator | |
) | |
[RecursiveCachingIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveCachingIterator | |
) | |
[NoRewindIterator] => ReflectionClass Object | |
( | |
[name] => NoRewindIterator | |
) | |
[AppendIterator] => ReflectionClass Object | |
( | |
[name] => AppendIterator | |
) | |
[InfiniteIterator] => ReflectionClass Object | |
( | |
[name] => InfiniteIterator | |
) | |
[RegexIterator] => ReflectionClass Object | |
( | |
[name] => RegexIterator | |
) | |
[RecursiveRegexIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveRegexIterator | |
) | |
[EmptyIterator] => ReflectionClass Object | |
( | |
[name] => EmptyIterator | |
) | |
[RecursiveTreeIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveTreeIterator | |
) | |
[ArrayObject] => ReflectionClass Object | |
( | |
[name] => ArrayObject | |
) | |
[ArrayIterator] => ReflectionClass Object | |
( | |
[name] => ArrayIterator | |
) | |
[RecursiveArrayIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveArrayIterator | |
) | |
[SplFileInfo] => ReflectionClass Object | |
( | |
[name] => SplFileInfo | |
) | |
[DirectoryIterator] => ReflectionClass Object | |
( | |
[name] => DirectoryIterator | |
) | |
[FilesystemIterator] => ReflectionClass Object | |
( | |
[name] => FilesystemIterator | |
) | |
[RecursiveDirectoryIterator] => ReflectionClass Object | |
( | |
[name] => RecursiveDirectoryIterator | |
) | |
[GlobIterator] => ReflectionClass Object | |
( | |
[name] => GlobIterator | |
) | |
[SplFileObject] => ReflectionClass Object | |
( | |
[name] => SplFileObject | |
) | |
[SplTempFileObject] => ReflectionClass Object | |
( | |
[name] => SplTempFileObject | |
) | |
[SplDoublyLinkedList] => ReflectionClass Object | |
( | |
[name] => SplDoublyLinkedList | |
) | |
[SplQueue] => ReflectionClass Object | |
( | |
[name] => SplQueue | |
) | |
[SplStack] => ReflectionClass Object | |
( | |
[name] => SplStack | |
) | |
[SplHeap] => ReflectionClass Object | |
( | |
[name] => SplHeap | |
) | |
[SplMinHeap] => ReflectionClass Object | |
( | |
[name] => SplMinHeap | |
) | |
[SplMaxHeap] => ReflectionClass Object | |
( | |
[name] => SplMaxHeap | |
) | |
[SplPriorityQueue] => ReflectionClass Object | |
( | |
[name] => SplPriorityQueue | |
) | |
[SplFixedArray] => ReflectionClass Object | |
( | |
[name] => SplFixedArray | |
) | |
[SplObserver] => ReflectionClass Object | |
( | |
[name] => SplObserver | |
) | |
[SplSubject] => ReflectionClass Object | |
( | |
[name] => SplSubject | |
) | |
[SplObjectStorage] => ReflectionClass Object | |
( | |
[name] => SplObjectStorage | |
) | |
[MultipleIterator] => ReflectionClass Object | |
( | |
[name] => MultipleIterator | |
) | |
[__PHP_Incomplete_Class] => ReflectionClass Object | |
( | |
[name] => __PHP_Incomplete_Class | |
) | |
[php_user_filter] => ReflectionClass Object | |
( | |
[name] => php_user_filter | |
) | |
[Directory] => ReflectionClass Object | |
( | |
[name] => Directory | |
) | |
[AssertionError] => ReflectionClass Object | |
( | |
[name] => AssertionError | |
) | |
[PHPTest] => ReflectionClass Object | |
( | |
[name] => PHPTest | |
) | |
) | |
) |
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 PHPTest { | |
interface MyTestInterface {} | |
class MyTestClass implements MyTestInterface {} | |
class MyExtendedClass extends MyTestClass {} | |
} | |
namespace PHPTest\SubLevel { | |
class TestA {} | |
} | |
namespace PHPTest\SecondSubLevel { | |
class TestB {} | |
class TestC {} | |
class TestD {} | |
} | |
namespace A\C { | |
const F = 3.14; | |
} | |
namespace A\B { | |
class FourthLevelClass {} | |
} | |
namespace { | |
class PHPTest {} | |
$namespaces = get_declared_namespaces(); | |
$namespaces[] = ""; | |
foreach ($namespaces as $namespace) { | |
print "===========================================\n"; | |
echo " Namespace: '", $namespace . "'" . PHP_EOL; | |
print "===========================================\n"; | |
$rn = new ReflectionNamespace($namespace); | |
print_r([ | |
"name" => $rn->getName(), | |
"internal" => $rn->isInternal(), | |
"user-defined" => $rn->isUserDefined(), | |
"parent" => $rn->getParentNamespace(), | |
"childs" => $rn->getChildNamespaces(), | |
"classes" => $rn->getClasses(), | |
]); | |
echo "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment