General Details
|
PHP (Hypertext Preprocess...
|
Posted 13 Days Ago
|
77 Views
|
Received 4 Ratings
|
|
Dynamic Parameters (Using Reflection)
Description
Allows for you to call a method of a class with the parameters in no particular order! Example:
function print($string, $size = 12, $color = 'red);
If you want to skip size, but you want to change the color... that is exactly what this class will do... eg...
$machine->call('print', array('string' => 'hello world', 'color' => 'green'));
And the optional size value will simply get passed a null,which will result in the default value of 12 being used ;-)
Have fun.
P.S. The original idea (though no code here is based off this) came from: http://www.phpclasses.org/browse/file/25345.html
Technical
Requires PHP 5.2 or something... basically a recent version of PHP 5 :-D
To use the class... see the examples below it in the source code. The class just needs to be inherited by any classes wanting to use it, and then call it's "call" method to use it's power :-D
When all the code below is run, it will show the following on your browser to demonstrate it works:
hello world
Fatal error: The parameter "string" is required! in {location of file} on line 78
Source Code
Comments
Please login to post comments. |
|
Gotta say I have no idea WHERE or WHY the hell this would be used, but still a pretty interesting piece of code, none-the-less.
|
|
Hi ya gunni,
Yeah i should really have done, eval is evil (plus error messages are messed up in it). But eval came to mind first and to be honest, this is only a quick script anyway so i'm not updating i anymore unless i get an urge to. It would need optimizing and more work adding to it before it's of any real benefit to anyone.
If you want to improve it, feel free.
Kind regards,
Scott
|
|
you should really prefer call_user_func_array() instead of eval() . And call() should return the return value of the method called.
|
|
Damn, looking over my code, i think i've spelt parameters wrong every time! lmao
|
|
Haha, i'm never sure where anything comes in handy but i learn it anyway. I never new reflection would come in handy lol
Kind regards,
Scott
|
|
Very nice! Not sure where this would come in handy :P But very well done.
|
More "PHP (Hypertext Preprocessor)" Source Codes By This Author
Recently Posted "PHP (Hypertext Preprocessor)" Source Codes
Recently Rated "PHP (Hypertext Preprocessor)" Source Codes
|