|
-
January 16th, 2009, 11:14 AM
#1
[RESOLVED] PHP: Mimic built in function
I must admit, that I am fascinated with method bind result
$stmt->bind_result($col1, $col2);
Because it can take non fixed number of arguments.
In this case those are variables, which were NOT created / declared anywhere before!
They also are referenced and get value later.
I've tried to recreate that behaviour, but failed!
PHP Code:
function xperiment() { $numargs = func_num_args(); $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { $arg_list[$i] &= rand(1, 100); echo "Argument $i is: " . $arg_list[$i] . NL; } }
xperiment($one, $two, $three);
echo "$one, $two, $three";
I can't even make it free of:
Code:
Notice: Undefined variable:....
And failed to reference it!
I think it would really be a fun, to "crack it"
Ipsens
-
January 16th, 2009, 02:46 PM
#2
Re: PHP: Mimic built in function
That's because you aren't declaring what $one, $two, and $three are when you pass them as variables to the function xperiment.
PHP Code:
$one = 'One'; $two = 'Two'; $three = 'Three';
xperiment($one, $two, $three);
//or xperiment('One', 'Two', 'Three');
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 16th, 2009, 02:50 PM
#3
Re: PHP: Mimic built in function
 Originally Posted by PeejAvery
That's because you aren't declaring what $one, $two, and $three are when you pass them as variables to the function xperiment.....
That is a point!
NOT to declare variables anywhere!
They FIRSTLY appear, like arguments supplied to that function:
PHP Code:
xperiment($one, $two, $three);
JUST like in a case of stmt_bind_result.
Ipsens
-
January 16th, 2009, 03:46 PM
#4
Re: PHP: Mimic built in function
Okay, I misread your first post.
The reason this happens is because of the mysqli class itself. I doubt you can recreate because of the need for variable declaration within PHP. If you were using C to write your own PHP class, then imitating it would be easy.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 16th, 2009, 04:04 PM
#5
Re: PHP: Mimic built in function
Actualy it is $stmt class in play, created by MySQLi class.
So..., that is final?
It can't be done!?
I wanted to create such function which would receive as many variables as I wanted.
That function would declare them and populate them with some values, by reference without returning them.
So I could just continue to use those vars normally inside PHP script.
Well, I guess it can't be done as PHP is created in C language.
Ipsens
-
January 16th, 2009, 04:24 PM
#6
Re: PHP: Mimic built in function
You can create a function that will receive an infinite number of variables. But, the data passed as the parameters must be defined.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 16th, 2009, 04:33 PM
#7
Re: PHP: Mimic built in function
 Originally Posted by PeejAvery
You can create a function that will receive an infinite number of variables. But, the data passed as the parameters must be defined.
Yes, I know that.
But, after that comes PHP's limitation.
Ipsens
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|