 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
NetTuts.com: Reflection in PHP
by Chris Cornutt April 19, 2013 @ 10:24:28
On NetTuts.com today there's a new tutorial talking about a part of PHP that can be quite powerful but isn't used too often - reflection in PHP. Using Reflection you can get information about your actual code and its elements without having to try to parse it yourself.
Reflection is generally defined as a program's ability to inspect itself and modify its logic at execution time. In less technical terms, reflection is asking an object to tell you about its properties and methods, and altering those members (even private ones). In this lesson, we'll dig into how this is accomplished, and when it might prove useful.
They provide a little context around the idea of "reflection" in programming languages and then jump right in with a few sample classes. They set up their "Nettuts", "Manager" and "Editor" classes and show how to use the ReflectionClass functionality to get their structure. The examples show how to get the class' methods, their properties and calling these methods using things like invoke and call_user_func.
voice your opinion now!
reflection tutorial introspection methods parameters invoke
Peter Meth: The Road to True North PHP ... Reflections
by Chris Cornutt October 08, 2012 @ 08:15:27
Peter Meth one of the organizers of the True North PHP Conference (happening at the beginning of November) has a new post sharing some of his experience as a (PHP) conference planner so far.
As you may or may not know I have been planning a conference called True North PHP with my friend Chris Hartjes. I wanted to blog about some of my experiences in planning the conference and reflect back on what brought me here. This blog is especially important to me since this is the first time I am organizing a conference and would appreciate all the feedback I can get. I hope to do several posts over the next month leading up to the conference.
He talks some about his own background in the programming industry and how, thanks to his renewed interest in PHP, he was able to connect with the community and start the idea of a Toronto-based conference. He mentions Confoo as a conference he enjoyed and one that pushed him forward to want something like that locally.
If you're in the Toronto area (or want to visit in early November) and you haven't checked out the True North PHP Conference yet - you definitely should. It's a great two days packed with PHP goodness and tickets are already on sale! (and here's the schedule).
voice your opinion now!
truenorthphp tnp12 toronto reflection conference petermeth
PHPMaster.com: Introspection and Reflection in PHP
by Chris Cornutt May 25, 2012 @ 14:03:57
On PHPMaster.com today there's an introduction to Reflection, a feature of PHP that allows you to peer into the code itself and find out metadata like class properties, scope levels and parent classes.
PHP introspection is a common feature in any programming language which allows object classes to be manipulated by the programmer. You'll find introspection particularly useful when you don't know which class or method you need to execute at design time. [...] During this article, you'll see a couple examples of how to use some of the most useful PHP's introspection function and a section dedicated to an API that offers functionality similar to introspection, the Reflection API.
They introduce you to a few different methods including class_exists, get_class and get_class_vars and method_exists. They also briefly mention the "ReflectionClass" that's a part of the PHP Reflection API and how it can be used to make an instance pointing to a current class.
voice your opinion now!
introspection reflection tutorial api metadata
Chris Hartjes' Blog: Metatesting Extending Your Testing Tools
by Chris Cornutt April 23, 2012 @ 11:27:02
Chris Hartjes has had a few posts about "metatesting" already and in this latest article he takes the series one more step. He looks at moving outside of the current toolset and expanding on them to meet your testing needs.
While PHPUnit is awesome out of the box, it still lacks some tools that are required to do things like test protected class methods or assign values to protected class attributes. Lucky for me we have an awesome testing engineer at Kaplan named Will Parker who has shown me some ways that they have extended PHPUnit itself to make testing certain things easier.
Chris talks about things like testing protected methods (easy thanks to a helper) and checking the value of a class property. The key to both of them lies in using PHP's own Reflection functionality to alter properties on the class objects themselves.
voice your opinion now!
metatesting extend tool phpunit reflection protected property
Slawek Lukasiewicz's Blog: Zend Framework Reflection
by Chris Cornutt May 31, 2011 @ 08:18:56
Slawek Lukasiewicz has a recent post to his blog looking at a tool that comes bundled with PHP that can help you find out more about your own code (or really any other piece of code out there) - the Reflection API. In his post he looks specifically at the functionality the Zend Framework has built on top of the base PHP API.
Zend Framework has own Reflection extension. It is mostly build upon genuine PHP Reflection API and extends existing features. The completely new Zend_Reflection module feature is introspection of docBlock tags.
He includes two code examples using this component of the framework - grabbing the docblock off of a specific method (and even how to grab specific tags from inside it) and how to grab the body content out of a given method, with or without the docblock attached.
voice your opinion now!
zendframework reflection docblock method
Gonzalo Ayuso's Blog: Reflection over PHPDoc with PHP
by Chris Cornutt April 04, 2011 @ 12:51:15
Gonzalo Ayuso has a new post to his blog today talking about a regular expression-laden script he's some up with to reflect over a PHP file and pull out the document's comments (PHPDoc-style).
I want to parse PHPDoc code. Let me explain a little bit what I want to do. Imagine a dummy function documented with PHPDoc. [...] PHP has a great reflection API, but as at least in the current PHP version (as far as I know) we only can get the PHPDoc as a string, without parse it. I need to get the parameters and the type of them with reflection. [...] But the type is different.
His script (based loosely on a bit of a component from the Zend Framework) parses the file and its comments and grabs the variable types from the PHPDoc blocks on each method and associates them.
If you're looking for a more mature solution than just this script, take a look at Docblox, a PHP 5.3 documentation generator.
voice your opinion now!
reflection tutorial phpdocumentor comment variable type
Eric Lamb's Blog: Practical PHP Reflection
by Chris Cornutt March 04, 2011 @ 12:23:28
Eric Lamb came up against an interesting situation recently and found that PHP's Reflection API was the best thing to come to his rescue.
The perfect problem where the Reflection API appears to be the perfect solution. For me this came up a couple months ago while I was working on a European zip code radius project that had to be built using one of those obfuscated and ill documented 3rd party commercial programs (nothing worse than when the platform is forced on you). So, I had to use this program that was intentionally encoded to prevent me from doing what I wanted to do. I couldn't even look at the code; it was completely obfuscated.
To illustrate his point, he gives examples of two built-in classes that PHP has and the result of their reflected output - SimpleXMLElement and DateTime. He shows how to get the structure of the class in general and how to use some of the more specific functions to get things like properties, methods and constants for the class. This is perfect for those undocumented features and isn't too far of a jump away from building out your own documentation.
voice your opinion now!
api reflection detail class tutorial
Box UK Labs: Dependency Injection and Reflection library
by Chris Cornutt December 21, 2010 @ 08:45:24
On the Box UK Labs site there's an interesting dependency injection tool that uses Reflection to get some of the work done.
Dependency injection is a well known concept, and there are currently a plethora of DI containers available from one of the interweb's many pipes. These include Symfony and Crafty, while the Zend Framework also has its own DI container. So why another? One of my personal goals as a developer is to make things so simple, even I can understand them. But most of the DI containers I've come across require too much configuration, and usually via XML - yuck! So how is ours different?
The tool, boxuk-di, makes use of the Addendum tool to create injectable objects easily accessed via a namespace. You can also use type hinting, scoping and annotations to do special things (like make singleton injection objects). The also mention how primitives are used as well as dispelling some of the misconceptions around reflection and this particular tool.
voice your opinion now!
reflection dependency injection library boxuklabs
|
Community Events
Don't see your event here? Let us know!
|