Coder Profile - Show off your skills, get a coder profile.
 
 
 
The Author
VBAssassin
Scott Thompson
Send A Message
Rating
7.75
out of 10
( 4 Ratings )
Please login to rate source codes.

Click here to register a free account with us.
General Details
PHP (Hypertext Preprocess...
Posted 13 Days Ago
77 Views
Received 4 Ratings
More Codes By This Author
Dynamic Parameters (Using...
Slime Wars Game v1
Pagination Class
Template Class (no evals...
Weighted Picking of URLs...
Articles By This Author
[PHP] - Lets kill the com...
How to use Memcache on Wi...
PHP Sessions = Member Dat...
Speed Up Delivery of your...
AJAX - When to use it?

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.
 
Craige     Posted 10 Days Ago
 
 
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.
 
VBAssassin     Posted 11 Days Ago
 
 
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
 
gunni     Posted 11 Days Ago
 
 
you should really prefer call_user_func_array() instead of eval() . And call() should
return the return value of the method called.
 
VBAssassin     Posted 12 Days Ago
 
 
Damn, looking over my code, i think i've spelt parameters wrong every time! lmao
 
VBAssassin     Posted 12 Days Ago
 
 
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
 
Izzmo     Posted 12 Days Ago
 
 
Very nice! Not sure where this would come in handy :P But very well done.
Page 1 of 1
More "PHP (Hypertext Preprocessor)" Source Codes By This Author
Recently Posted "PHP (Hypertext Preprocessor)" Source Codes
Recently Rated "PHP (Hypertext Preprocessor)" Source Codes
 
 
Latest News About Coder Profile
Coder Profile Poll
How often do you write code on average per week?

< 5 hours
5 to 20 hours
21 to 30 hours
31 to 40 hours
> 40 hours


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
19 Days Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright � 2007 - 2008, Scott Thompson, All Rights Reserved