Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Mustafa Magdi:
Introduction to PHP Reflection API
Dec 28, 2017 @ 11:55:43

Mustafa Magdi has written up a tutorial that introduces you to PHP's Reflection API, functionality included with the language that allows for introspection of the code and some real-time modifications.

When I started PHP coding, I wasn’t aware of the power of Reflection API and the main reason is that I didn’t need it to design my simple class, module or even my package, then I started to find it in many areas playing a major role. So in this part we will introduce Reflection API.

The post is then broken down into a few sections covering the basics of the Reflection functionality, examples of it in use and some other references you can use to get more information. Code examples are included to show how to use the API to do things like:

  • get the parent class for a current class
  • get the docblock comment of a method
  • making private methods available for testing

He also links to two packages that make use of the Reflection API heavily to generate documentation and build a dependency injection container.

tagged: reflection api introduction tutorial beginner

Link: https://medium.com/@MustafaMagdi/introduction-to-php-reflection-api-4af07cc17db4