![]() |
Passing multiple arguments to a function via one variable.
Without setting up null possibilities for every argument, is it possible to pass multiple arguments to a function call via one variables?
ie, in my singleton loader, I have the following; PHP Code:
So I thought, what if you reconstructed the array into a string, using the arguments quoting convention of "arg", "arg2", "etc". Should've known before I started trying that it wouldn't work. It just passes it as a string, like it should. So... I wonder if there's any way to pass multiple arguments to a function call or object call, with only one variable? This is more for curiosity's sake than anything. I don't have any classes at this point that I even pass a single argument too when I call them. Just one of those random thoughts, "can I do that??". -m |
To try and simplify that further, I guess what I'm trying to do is have $szArgs interpreted before it gets passed to the method.
|
How about this guide?
|
Oh, oh, I see how it is.
That article never existed before. I posted this, and you were all, hey, why don't I write an article about it, and then you made it look like you posted that way back last year, and that other people found it highly useful as well. ALL just to make me look silly, didn't ya? Didn't YA?! Thank you. |
Haha! :-) Something like that! I can be quite devilish in my spare time.
|
Can I do this through two function calls? Ie, if my first call is a static
core::load('module', 'arg1', 'arg2'); Can I then, from within load somehow pass arg1 and arg2? $pPointer = new object($args) ? I know how to grab the muliple arguments from load using func_get_args/func_num_args, but then I want to pass it on again, using a single variable if possible. Or do I have to do something like PHP Code:
-m |
Excuse me if I haven't well understood but why don't you use something like that:
PHP Code:
PHP Code:
|
That's not a bad idea at all. I guess I was looking for a way to pass multiple arguments via my load() method without having to do any extra coding in the object itself to handle it. That way my objects could be clean, and the load method would handle all the organization. So I supposed with that idea in mind I could do something such as
PHP Code:
-m |
Rather than re-wiring all of your classes to accept a single argument in the form of an array, you could use PHP5's Reflection API to create a new object instance with our arguments like:
PHP Code:
|
Okay, *that* may be a little beyond my scope at this point. I like to fully understand the things I'm doing before I do them, otherwise when things break I can sit there banging my head for ever before I find one simple little mistake I made haha. I'm checking out the manual for that right now, and I just got my book today, "PHP Objects, Patterns and Practice" which has a bit on the Reflection API, so I'll look into that, and see what I learn. Thanks!
-m |
Okay, so I'm into the section of the Reflection API in my book now. You could've told me your code works just as is! haha. ;-)
PHP Code:
PHP Code:
-m |
| All times are GMT. The time now is 05:58 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0