 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
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
Sebastian Bergmann's Blog: Scalar Type Hints in PHP 5.3.99
by Chris Cornutt November 24, 2010 @ 10:04:06
In the theme of other recent posts mentioning the scalar type hinting that has been included in the main line of code that is headed towards the next PHP release, Sebastian Bergmann has a new post about their inclusion in PHP 5.3.99 (yes, that's PHP 5.4) and the new syntax it introduces.
In a nutshell, this means that PHP 5.3.99 introduces new syntax -- scalar type hints -- but no new semantics. The latter can either be implemented as an extension written in C/C++, in userland PHP code, or in a tool that statically analyzes the code.
He includes an example fro userland with a "php_check_parameters" function that looks at the arguments of the current method and uses Reflection to check against the type hints for the correct value type.
voice your opinion now!
reflection scalar type hint feature userland
Simas Toleikis's Blog: Idea for a PHP Validator
by Chris Cornutt October 08, 2010 @ 13:48:26
Simas Toleikis has posted an interesting idea for a validator that would look at the incoming source of an application/script and determine what the requirements for it might be.
How about creating a PHP code validator? Got this idea by looking at tokenizer and reflection extensions. I doubt I will find the time to work on this myself but then someone else might be interested to pick it up. From user's point of view there will be a form made of a large textarea box and a single file upload input. One could paste code snippet on that textarea or upload a ZIP'ed source code archive (or a single .php file) for validation.
His proposed result would show a list of "Required Extensions", PHP versions, E_STRICT compatibility and possibly total lines of code in the project. He points out a few issues that might pop up in writing such a tool such as the requirement for it to be able to use the tokenizer extension itself (a sort of catch-22 since it's not always installed).
voice your opinion now!
validator idea requirements application reflection tokenizer
Stanislav Malyshev's Blog: Adding new extensions to Zend Studio
by Chris Cornutt September 08, 2010 @ 08:32:31
In a new post to his blog Stanislav Malyshev talks about how Zend Studio users can get the tool to recognize new extensions by adding in stubs with PHPDocumentor markup.
If you have some extension, create stub file with PHPDOC descriptions [...] for each extension function, Studio will know to pick it up. You can put this file into Studio's prototypes directory - easiest way to find it is just write something like chdir() anywhere, select the name and press F3, the directory of the file that you'll get is the one you need.
Not wanting to have to generate all of the stubs himself, he created the Reflector script that will, when pointed at an extension, create the stub file with definitions for each method it can use. There's also the generator script that's a part of Zend Studio that works similarly.
voice your opinion now!
zendstudio extension reflection docblock
Chris Tankersley's Blog: Getting Started with Reflection
by Chris Cornutt September 03, 2010 @ 14:12:13
Chris Tankersley has a new post to how blog looking at a powerful but sometimes seldom used feature of PHP - Reflection. His post introduces you to some of the basics you can use to have your code find out more about itself.
Reflection is a metaprogramming construct that allows a program to look into itself and do a multitude of different things - gain meaning, watch execution, call code, or even provide feedback. [...] With PHP 5, PHP gained a robust reflection class that allows a developer to gain access to just about every aspect of an object and interact with it. The key is figuring out what is available, and then exploiting it to gain additional benefits.
He gives examples from his project where it uses the ReflectionClass feature to pull in the values of a class including properties and methods in a class (a set of ReflectionMethods). Some code is provided to make the examples a bit more clear.
voice your opinion now!
reflection introduction tutorial reflectionclass reflectionmethod
Sebastian Bergmann's Blog: Testing Your Privates
by Chris Cornutt February 09, 2010 @ 11:48:42
In a new post to his blog today Sebastian Bergmann looks at a way you can test your privates (no, not that) - private methods in your classes with PHPUnit. The key lies in the Reflection API.
One question I get over and over again when talking about Unit Testing is this: "How do I test the private attributes and methods of my objects?" [...] PHP 5.3.2 introduces the ReflectionMethod::setAccessible() method to allow the invocation of protected and private methods through the Reflection API.
This method lets you, at runtime, change the access level on the method away from private or protected and down to public so the contents can be executed normally. Though he warns one thing about doing it this way - just because you can, doesn't mean it's a good thing. You application is meant to be tested in a certain way and you should probably stick to that.
voice your opinion now!
test private method tutorial reflection
|
Community Events
Don't see your event here? Let us know!
|