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

Matthew Weir O'Phinney's Blog:
PHP 5's Reflection API
Oct 09, 2006 @ 18:37:00

In his latest blog post, Matthew Weir O'Phinney shares some of his newfound love for the Reflection API that PHP5 brings to the table:

When I first read about the Reflection API in a pre-PHP 5 changelog, my initial reaction was, "who cares?" I simply failed to see how it was a useful addition to the language. Having done some projects recently that needed to know something about the classes they are using, I now understand when and how it can be used.

It shines when you need to work with classes that may not be defined when you write your code -- any code that dispatches to other classes, basically.

To emphasize the point, he lists a few things you can do with the API, including determine if a method exists in a class and instantiate an object instance with a variable number of arguments to the constructor. He also includes a code example, showing a simple method of getting all of the methods on a class.

tagged: relfection api php5 classes object method example relfection api php5 classes object method example

Link:

Matthew Weir O'Phinney's Blog:
PHP 5's Reflection API
Oct 09, 2006 @ 18:37:00

In his latest blog post, Matthew Weir O'Phinney shares some of his newfound love for the Reflection API that PHP5 brings to the table:

When I first read about the Reflection API in a pre-PHP 5 changelog, my initial reaction was, "who cares?" I simply failed to see how it was a useful addition to the language. Having done some projects recently that needed to know something about the classes they are using, I now understand when and how it can be used.

It shines when you need to work with classes that may not be defined when you write your code -- any code that dispatches to other classes, basically.

To emphasize the point, he lists a few things you can do with the API, including determine if a method exists in a class and instantiate an object instance with a variable number of arguments to the constructor. He also includes a code example, showing a simple method of getting all of the methods on a class.

tagged: relfection api php5 classes object method example relfection api php5 classes object method example

Link:


Trending Topics: