[PHP] pass by reference variable length args
hi all, i'm trying to write a wrapper function for mysqli_stmt_bind_results. and expect it to work the same way it accepts and bind results to the original function. the problem is, i couldn't find a way to pass the args by reference via func_get_args and register the out put from call_user_func_array to the caller scope.. any idea? here goes few lines which i'm trying hard for past 48 hours.. with no luck.. :( class stmt { private $stmt; public function bind_result() { $argsToBindResult = func_get_args(); $argList = array($this-stmt); $argList = array_merge($argList, $argsToBindResult); call_user_func_array('mysqli_stmt_bind_result', $argList); } } $stmt-prepare('SELECT name,email FROM users WHERE id = ?'); $stmt-bind_param('i',2); .. .. $stmt-bind_result($name,$email); echo $name,$email; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference variable length args
viraj wrote: hi all, i'm trying to write a wrapper function for mysqli_stmt_bind_results. and expect it to work the same way it accepts and bind results to the original function. the problem is, i couldn't find a way to pass the args by reference via func_get_args and register the out put from call_user_func_array to the caller scope.. any idea? here goes few lines which i'm trying hard for past 48 hours.. with no luck.. :( class stmt { private $stmt; public function bind_result() { $argsToBindResult = func_get_args(); $argList = array($this-stmt); $argList = array_merge($argList, $argsToBindResult); call_user_func_array('mysqli_stmt_bind_result', $argList); } } $stmt-prepare('SELECT name,email FROM users WHERE id = ?'); $stmt-bind_param('i',2); .. .. $stmt-bind_result($name,$email); echo $name,$email; You're out of luck for using the func_get_args() call. The following method (albeit a dirty method) works: ?php function bind_stuff( $arg1, $arg2=null, $arg3=null, $arg4=null, $arg5=null, $arg6=null, $arg7=null, $arg8=null, $arg9=null ) { for( $i = 1; $i = 9; $i++ ) { ${'arg'.$i} = 'bound'.$i; } } bind_stuff( $name, $email ); echo $name.\n; echo $email.\n; ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference variable length args
thanks rob! here goes the working method. public function bind_result($arg1=null,$arg2=null,$arg3=null) { $numArgs = func_num_args(); $args = array(); for ($i=1; $i= $numArgs; $i++) { $args['arg' . $i] = ${'arg'.$i}; } call_user_func_array('mysqli_stmt_bind_result',array_merge(array($this-stmt),$args)); } $stmt-bind_result($id, $test); $stmt-fetch(); echo $id, $test; ~viraj On Wed, Jan 6, 2010 at 10:01 AM, Robert Cummings rob...@interjinn.com wrote: viraj wrote: hi all, i'm trying to write a wrapper function for mysqli_stmt_bind_results. and expect it to work the same way it accepts and bind results to the original function. the problem is, i couldn't find a way to pass the args by reference via func_get_args and register the out put from call_user_func_array to the caller scope.. any idea? here goes few lines which i'm trying hard for past 48 hours.. with no luck.. :( class stmt { private $stmt; public function bind_result() { $argsToBindResult = func_get_args(); $argList = array($this-stmt); $argList = array_merge($argList, $argsToBindResult); call_user_func_array('mysqli_stmt_bind_result', $argList); } } $stmt-prepare('SELECT name,email FROM users WHERE id = ?'); $stmt-bind_param('i',2); .. .. $stmt-bind_result($name,$email); echo $name,$email; You're out of luck for using the func_get_args() call. The following method (albeit a dirty method) works: ?php function bind_stuff( $arg1, $arg2=null, $arg3=null, $arg4=null, $arg5=null, $arg6=null, $arg7=null, $arg8=null, $arg9=null ) { for( $i = 1; $i = 9; $i++ ) { ${'arg'.$i} = 'bound'.$i; } } bind_stuff( $name, $email ); echo $name.\n; echo $email.\n; ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference variable length args
if func_get_args supports pass by reference, we could have avoid the loop and pre-defined arg list. something like.. extract(func_get_args) :D cheers! ~viraj On Wed, Jan 6, 2010 at 11:04 AM, viraj kali...@gmail.com wrote: thanks rob! here goes the working method. public function bind_result($arg1=null,$arg2=null,$arg3=null) { $numArgs = func_num_args(); $args = array(); for ($i=1; $i= $numArgs; $i++) { $args['arg' . $i] = ${'arg'.$i}; } call_user_func_array('mysqli_stmt_bind_result',array_merge(array($this-stmt),$args)); } $stmt-bind_result($id, $test); $stmt-fetch(); echo $id, $test; ~viraj On Wed, Jan 6, 2010 at 10:01 AM, Robert Cummings rob...@interjinn.com wrote: viraj wrote: hi all, i'm trying to write a wrapper function for mysqli_stmt_bind_results. and expect it to work the same way it accepts and bind results to the original function. the problem is, i couldn't find a way to pass the args by reference via func_get_args and register the out put from call_user_func_array to the caller scope.. any idea? here goes few lines which i'm trying hard for past 48 hours.. with no luck.. :( class stmt { private $stmt; public function bind_result() { $argsToBindResult = func_get_args(); $argList = array($this-stmt); $argList = array_merge($argList, $argsToBindResult); call_user_func_array('mysqli_stmt_bind_result', $argList); } } $stmt-prepare('SELECT name,email FROM users WHERE id = ?'); $stmt-bind_param('i',2); .. .. $stmt-bind_result($name,$email); echo $name,$email; You're out of luck for using the func_get_args() call. The following method (albeit a dirty method) works: ?php function bind_stuff( $arg1, $arg2=null, $arg3=null, $arg4=null, $arg5=null, $arg6=null, $arg7=null, $arg8=null, $arg9=null ) { for( $i = 1; $i = 9; $i++ ) { ${'arg'.$i} = 'bound'.$i; } } bind_stuff( $name, $email ); echo $name.\n; echo $email.\n; ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference variable length args
viraj wrote: if func_get_args supports pass by reference, we could have avoid the loop and pre-defined arg list. something like.. extract(func_get_args) :D Absolute! I'm not sure why there isn't some kind of way to retrieve a reference in this manner, but I suspect it's related to knowing which parameters were set as reference appropriate values. For instance contrast the following: bind_stuff( $id, $test ); Versus the following: bind_stuff( 5, $test ); Defining the function parameters to use references will generate a fatal error when 5 is passed since this is a fatal error. How then to enable variable args to achieve the same result? I guess one could ask PHP to support something like the following: $args = func_bind_args( array( true, true ) ); Where $args would then contain a reference where the corresponding index was set to true in the argument list. Since this isn't very variable, then the last index set would denote the default for all other args. Thus the example above could be shortened: $args = func_bind_args( array( true ) ); Or even: $args = func_bind_args( true ); Since this is run-time too, then PHP could generate an E_WARNING instead of E_FATAL and bind a copy instead when no reference was passed. On further thought, the current func_get_args() could be adapted in this manner since it currently accepts no arguments. Anyways... just thoughts. I hit this problem in the past too :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference
Kevin Waterson wrote: This one time, at band camp, Justin French [EMAIL PROTECTED] wrote: In other words, you HTML source looks like this: img src='images.php?id=45' NOT img src='{RAW BINARY DATA HERE}' Kevin, et all. Can this be posible? I mean img src='{RAWDATA}' where RAWDATA beening any image? Cesar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference
Kevin Waterson wrote: This one time, at band camp, Tom Rogers [EMAIL PROTECTED] wrote: php can output the stream without having to save it to a file first if that is what is worrying you. That was sorta my concern, but not so much as a file, does it copy to memory anywhere, or, is it a direct stream to the browser? Well, you're making a few copies doing it through PHP. Or possibly just one. When PHP fetches it from the DB, it's stored in a variable (and the data *may* be stored in an intermediate form by the PHP internals, but I certainly don't know for sure. My gut says that it is, though.). Then you output it to the browser. Yes, this is somewhat inefficient, but the only way I can think of to make it more efficient would be to make the images files and have the webserver send them directly. I suppose this terraserver might be able to stream the data as it gets it from the DB server, but it's still makign a copy. It just happens to be very small pieces of the image, outputted as they get to the server. While this is kinda cool, it seems a bit too far to go for normal applications. If you're worried this much about speed, you shouldn't be storing the images in the DB in the first place. Storing them as files will nearly always be faster than any other method (unless you've cached them in RAM somehow ;-). -- paperCrane Justin Patrin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pass by reference
In a recent discussion about the MS terra server it was mentioned this could not be done with PHP because the terraserver has special front-end code that allows images to be passed by reference, so the image data goes directly from the database access back end to the client browser, without having to be copied to and from an intermediate middleware layer. The implication is that the 'middle layer' (PHP) would slow things down to an unusable state. so, when I extract an image from the database and echo it to a webpage, is there any copying done? or is it a direct stream to the webpage? Kind regards Kevin -- __ (_ \ _) ) | / / _ ) / _ | / ___) / _ ) | | ( (/ / ( ( | |( (___ ( (/ / |_| \) \_||_| \) \) Kevin Waterson Port Macquarie, Australia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference
On Friday, January 23, 2004, at 03:17 PM, Kevin Waterson wrote: The implication is that the 'middle layer' (PHP) would slow things down to an unusable state. so, when I extract an image from the database and echo it to a webpage, is there any copying done? or is it a direct stream to the webpage? I don't think you ever extract image data direct from a database and echo it to a web (HTML) page do you? Typically you call a php script which outputs the correct mimetype for the image, and passes the image data through to the user agent. In other words, you HTML source looks like this: img src='images.php?id=45' NOT img src='{RAW BINARY DATA HERE}' I don't know if this helps or not :) Justin French -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference
This one time, at band camp, Justin French [EMAIL PROTECTED] wrote: In other words, you HTML source looks like this: img src='images.php?id=45' NOT img src='{RAW BINARY DATA HERE}' Yes, but how is this different from anything the terraserver is doing? when the images.php script is called if would do something like Select the image data from the database header(Content-type: image/jpeg); echo $row['image_data']; surely this is as fast as we go, or is this adding an extra layer as suggested in the first mail? Kind regards Kevin -- __ (_ \ _) ) | / / _ ) / _ | / ___) / _ ) | | ( (/ / ( ( | |( (___ ( (/ / |_| \) \_||_| \) \) Kevin Waterson Port Macquarie, Australia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference
Hi, Friday, January 23, 2004, 2:17:07 PM, you wrote: KW In a recent discussion about the MS terra server it was mentioned KW this could not be done with PHP because the terraserver KW has special front-end code that allows images to be passed by reference, KW so the image data goes directly from the database access back end to the KW client browser, without having to be copied to and from an intermediate KW middleware layer. KW The implication is that the 'middle layer' (PHP) would slow things down KW to an unusable state. so, when I extract an image from the database and KW echo it to a webpage, is there any copying done? or is it a direct stream to the webpage? KW Kind regards KW Kevin KW -- KW __ KW (_ \ KW _) ) KW | / / _ ) / _ | / ___) / _ ) KW | | ( (/ / ( ( | |( (___ ( (/ / KW |_| \) \_||_| \) \) KW Kevin Waterson KW Port Macquarie, Australia What does the image tag look like on the request to the terra server ? php can output the stream without having to save it to a file first if that is what is worrying you. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference
This one time, at band camp, Tom Rogers [EMAIL PROTECTED] wrote: php can output the stream without having to save it to a file first if that is what is worrying you. That was sorta my concern, but not so much as a file, does it copy to memory anywhere, or, is it a direct stream to the browser? Kind regards Kevin -- __ (_ \ _) ) | / / _ ) / _ | / ___) / _ ) | | ( (/ / ( ( | |( (___ ( (/ / |_| \) \_||_| \) \) Kevin Waterson Port Macquarie, Australia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] pass by reference
Hi, Friday, January 23, 2004, 3:18:06 PM, you wrote: KW This one time, at band camp, Tom Rogers [EMAIL PROTECTED] wrote: php can output the stream without having to save it to a file first if that is what is worrying you. KW That was sorta my concern, but not so much as a file, does it copy to KW memory anywhere, or, is it a direct stream to the browser? KW Kind regards KW Kevin I am pretty sure mysql cannot do that yet and PHP has to put it to memory first. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] pass by reference
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I did a complex class that works with XML parsing and complex structured where I used references extensivly and now I'm surprised with: Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of array_push(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. I can't modify the php.ini since I'm in a shared but the problem is deeper. Why was it deprecated ? what replaced it ? is there any work arround ? My 200 lines of code without references could take much, much longer and be much, much more messy. Any ideas ? Thanks. - -- Pupeno: [EMAIL PROTECTED] http://www.pupeno.com - --- Help the hungry children of Argentina, please go to (and make it your homepage): http://www.porloschicos.com/servlet/PorLosChicos?comando=donar -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE+I02cLr8z5XzmSDQRAs/0AKCyf+UG0uZdbwG30WFU0UUNVWO7BwCgnCn5 2LmOOJi8uX+1dOqUfCTatSE= =5obN -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference
Hi, Tuesday, January 14, 2003, 9:36:57 AM, you wrote: P -BEGIN PGP SIGNED MESSAGE- P Hash: SHA1 P I did a complex class that works with XML parsing and complex structured where P I used references extensivly and now I'm surprised with: P Warning: Call-time pass-by-reference has been deprecated - argument passed by P value; If you would like to pass it by reference, modify the declaration of P array_push(). If you would like to enable call-time pass-by-reference, you P can set allow_call_time_pass_reference to true in your INI file. However, P future versions may not support this any longer. P I can't modify the php.ini since I'm in a shared but the problem is deeper. P Why was it deprecated ? what replaced it ? is there any work arround ? P My 200 lines of code without references could take much, much longer and be P much, much more messy. P Any ideas ? P Thanks. P - -- P Pupeno: [EMAIL PROTECTED] P http://www.pupeno.com P - --- P Help the hungry children of Argentina, P please go to (and make it your homepage): P http://www.porloschicos.com/servlet/PorLosChicos?comando=donar P -BEGIN PGP SIGNATURE- P Version: GnuPG v1.0.7 (GNU/Linux) P iD8DBQE+I02cLr8z5XzmSDQRAs/0AKCyf+UG0uZdbwG30WFU0UUNVWO7BwCgnCn5 P 2LmOOJi8uX+1dOqUfCTatSE= P =5obN P -END PGP SIGNATURE- I am sure array_push accepts the array as a reference so there is no need to use the operator in the call. At least thats how it works in a simple class. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pass by reference
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Monday 13 January 2003 20:01, Tom Rogers wrote: Hi, Tuesday, January 14, 2003, 9:36:57 AM, you wrote: P -BEGIN PGP SIGNED MESSAGE- P Hash: SHA1 P I did a complex class that works with XML parsing and complex structured where P I used references extensivly and now I'm surprised with: P Warning: Call-time pass-by-reference has been deprecated - argument passed by P value; If you would like to pass it by reference, modify the declaration of P array_push(). If you would like to enable call-time pass-by-reference, you P can set allow_call_time_pass_reference to true in your INI file. However, P future versions may not support this any longer. P I can't modify the php.ini since I'm in a shared but the problem is deeper. P Why was it deprecated ? what replaced it ? is there any work arround ? P My 200 lines of code without references could take much, much longer and be P much, much more messy. P Any ideas ? P Thanks. P - -- P Pupeno: [EMAIL PROTECTED] P http://www.pupeno.com P - --- P Help the hungry children of Argentina, P please go to (and make it your homepage): P http://www.porloschicos.com/servlet/PorLosChicos?comando=donar P -BEGIN PGP SIGNATURE- P Version: GnuPG v1.0.7 (GNU/Linux) P iD8DBQE+I02cLr8z5XzmSDQRAs/0AKCyf+UG0uZdbwG30WFU0UUNVWO7BwCgnCn5 P 2LmOOJi8uX+1dOqUfCTatSE= P =5obN P -END PGP SIGNATURE- I am sure array_push accepts the array as a reference so there is no need to use the operator in the call. At least thats how it works in a simple class. No, I mean, what you're pushing inside the array is a reference: array_push($anArrayOfReferences, $thisIsAVariable); that doesn't work, but I replaced by $anArrayOfReferences[count($anArrayOfReferences)] = $thisIsAVariable; Thanks :) - -- Pupeno: [EMAIL PROTECTED] http://www.pupeno.com - --- Help the hungry children of Argentina, please go to (and make it your homepage): http://www.porloschicos.com/servlet/PorLosChicos?comando=donar -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE+I2FvLr8z5XzmSDQRAjjOAKCm0pwkFAVC8vFfF2r8v/enZp4NhwCffIfV x0ipECbUUmn72eJbEw0eg60= =oFaa -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] pass by reference
Hi, Tuesday, January 14, 2003, 11:01:33 AM, you wrote: P -BEGIN PGP SIGNED MESSAGE- P Hash: SHA1 P On Monday 13 January 2003 20:01, Tom Rogers wrote: Hi, Tuesday, January 14, 2003, 9:36:57 AM, you wrote: P -BEGIN PGP SIGNED MESSAGE- P Hash: SHA1 P I did a complex class that works with XML parsing and complex structured where P I used references extensivly and now I'm surprised with: P Warning: Call-time pass-by-reference has been deprecated - argument passed by P value; If you would like to pass it by reference, modify the declaration of P array_push(). If you would like to enable call-time pass-by-reference, you P can set allow_call_time_pass_reference to true in your INI file. However, P future versions may not support this any longer. P I can't modify the php.ini since I'm in a shared but the problem is deeper. P Why was it deprecated ? what replaced it ? is there any work arround ? P My 200 lines of code without references could take much, much longer and be P much, much more messy. P Any ideas ? P Thanks. P - -- P Pupeno: [EMAIL PROTECTED] P http://www.pupeno.com P - --- P Help the hungry children of Argentina, P please go to (and make it your homepage): P http://www.porloschicos.com/servlet/PorLosChicos?comando=donar P -BEGIN PGP SIGNATURE- P Version: GnuPG v1.0.7 (GNU/Linux) P iD8DBQE+I02cLr8z5XzmSDQRAs/0AKCyf+UG0uZdbwG30WFU0UUNVWO7BwCgnCn5 P 2LmOOJi8uX+1dOqUfCTatSE= P =5obN P -END PGP SIGNATURE- I am sure array_push accepts the array as a reference so there is no need to use the operator in the call. At least thats how it works in a simple class. P No, I mean, what you're pushing inside the array is a reference: P array_push($anArrayOfReferences, $thisIsAVariable); P that doesn't work, but I replaced by P $anArrayOfReferences[count($anArrayOfReferences)] = $thisIsAVariable; P Thanks :) Ok :) These 2 functions will do what you want I think... function array_ref_push($array,$ref){ $array[] = $ref; } function array_ref_pop($array){ $r = $array[count($array)-1]; array_pop($array); //throw away a real pop return $r; } //Testing $stack = array(); $var = 1; array_ref_push($stack,$var); echo 'pre'; print_r($stack); echo '/pre'; $var = 2; echo 'pre'; print_r($stack); echo '/pre'; $var2 = array_ref_pop($stack); echo 'var2 = '.$var2.'br'; $var = 3; echo 'var2 = '.$var2.'br'; echo 'pre'; print_r($stack); echo '/pre'; -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php