From wdwtest at gmail.com Fri Jan 3 03:51:59 2014 From: wdwtest at gmail.com (wdwtest at gmail.com) Date: Fri, 3 Jan 2014 01:51:59 -0700 Subject: [nycphp-talk] wdwtest@gmail.com is inviting you to wdwindia.com Message-ID: <201401030851.s038pxl7026353@p3nlhg1350.shr.prod.phx3.secureserver.net> You are invited to wdwindia.com Attached message: Join now This invite was sent using OpenInviter technology. From ron at vnetworx.net Mon Jan 27 18:43:41 2014 From: ron at vnetworx.net (Ron Guerin) Date: Mon, 27 Jan 2014 18:43:41 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} Message-ID: <52E6EF2D.5090609@vnetworx.net> Is the only name I've found for this: ${'foo'.$i} Which, if $i is 2, gives the value of the variable $foo2 Since "variable composition" only has one hit in Google though, there's got to be another name for it. Anyone know what that might be? - Ron From jeff at jeffslutz.com Mon Jan 27 18:46:18 2014 From: jeff at jeffslutz.com (Jeff Slutz) Date: Mon, 27 Jan 2014 16:46:18 -0700 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: <52E6EF2D.5090609@vnetworx.net> References: <52E6EF2D.5090609@vnetworx.net> Message-ID: I've known it by the term variable variables. http://www.php.net/manual/en/language.variables.variable.php JS -- Jeff Slutz JSLEUTH LLC jeff at jeffslutz.com On Mon, Jan 27, 2014 at 4:43 PM, Ron Guerin wrote: > Is the only name I've found for this: ${'foo'.$i} > > Which, if $i is 2, gives the value of the variable $foo2 > > Since "variable composition" only has one hit in Google though, there's > got to be another name for it. Anyone know what that might be? > > - Ron > _______________________________________________ > New York PHP User Group Community Talk Mailing List > http://lists.nyphp.org/mailman/listinfo/talk > > http://www.nyphp.org/show-participation > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ron at vnetworx.net Mon Jan 27 20:02:22 2014 From: ron at vnetworx.net (Ron Guerin) Date: Mon, 27 Jan 2014 20:02:22 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: References: <52E6EF2D.5090609@vnetworx.net> Message-ID: <52E7019E.2050600@vnetworx.net> On 01/27/2014 06:46 PM, Jeff Slutz wrote: > I've known it by the term variable variables. > > http://www.php.net/manual/en/language.variables.variable.php I /knew/ I was asking a stupid question... I know $$foo is a "variable variable", but for some reason I didn't connect it with ${'foo'.$i} . Thanks! - Ron From justin at justinhileman.info Mon Jan 27 21:44:17 2014 From: justin at justinhileman.info (justin) Date: Mon, 27 Jan 2014 21:44:17 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: <52E7019E.2050600@vnetworx.net> References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> Message-ID: On Monday, January 27, 2014, Ron Guerin wrote: > On 01/27/2014 06:46 PM, Jeff Slutz wrote: > > I've known it by the term variable variables. > > > > http://www.php.net/manual/en/language.variables.variable.php > > I /knew/ I was asking a stupid question... I know $$foo is a "variable > variable", but for some reason I didn't connect it with ${'foo'.$i} . > The best thing ever written on the subject of variable variables: http://www.reddit.com/r/programming/comments/dst56/today_i_learned_about_php_variable_variables/c12np38 --justin -- http://justinhileman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ron at vnetworx.net Wed Jan 29 12:07:20 2014 From: ron at vnetworx.net (Ron Guerin) Date: Wed, 29 Jan 2014 12:07:20 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> Message-ID: <52E93548.2000205@vnetworx.net> On 01/27/2014 09:44 PM, justin wrote: > > On Monday, January 27, 2014, Ron Guerin > wrote: > > On 01/27/2014 06:46 PM, Jeff Slutz wrote: > > I've known it by the term variable variables. > > > > http://www.php.net/manual/en/language.variables.variable.php > > I /knew/ I was asking a stupid question... I know $$foo is a "variable > variable", but for some reason I didn't connect it with ${'foo'.$i} . > > The best thing ever written on the subject of variable variables: > > http://www.reddit.com/r/programming/comments/dst56/today_i_learned_about_php_variable_variables/c12np38 Wow. That's some scary stuff there. - Ron -- Join the NY Metro Area Tech Discussion! http://lists.luny.org/mailman/listinfo/talk From jeff at jeffslutz.com Wed Jan 29 13:45:49 2014 From: jeff at jeffslutz.com (Jeff Slutz) Date: Wed, 29 Jan 2014 11:45:49 -0700 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: <52E93548.2000205@vnetworx.net> References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> <52E93548.2000205@vnetworx.net> Message-ID: That's awesome! I love the response: can we hang this guy, I'm pretty sure he's a witch. :) -- Jeff Slutz JSLEUTH LLC 2105 N Fork Drive Lafayette, CO 80026 c. 970.443.9390 jeff at jeffslutz.com On Wed, Jan 29, 2014 at 10:07 AM, Ron Guerin wrote: > On 01/27/2014 09:44 PM, justin wrote: > > > > On Monday, January 27, 2014, Ron Guerin > > wrote: > > > > On 01/27/2014 06:46 PM, Jeff Slutz wrote: > > > I've known it by the term variable variables. > > > > > > http://www.php.net/manual/en/language.variables.variable.php > > > > I /knew/ I was asking a stupid question... I know $$foo is a > "variable > > variable", but for some reason I didn't connect it with ${'foo'.$i} . > > > > The best thing ever written on the subject of variable variables: > > > > > http://www.reddit.com/r/programming/comments/dst56/today_i_learned_about_php_variable_variables/c12np38 > > Wow. That's some scary stuff there. > > - Ron > > -- > Join the NY Metro Area Tech Discussion! > http://lists.luny.org/mailman/listinfo/talk > _______________________________________________ > New York PHP User Group Community Talk Mailing List > http://lists.nyphp.org/mailman/listinfo/talk > > http://www.nyphp.org/show-participation > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbaltz at altzman.com Thu Jan 30 12:12:14 2014 From: jbaltz at altzman.com (Jerry B. Altzman) Date: Thu, 30 Jan 2014 12:12:14 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: <52E93548.2000205@vnetworx.net> References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> <52E93548.2000205@vnetworx.net> Message-ID: <52EA87EE.7090805@altzman.com> on 1/29/2014 12:07 PM Ron Guerin said the following: > On 01/27/2014 09:44 PM, justin wrote: >> http://www.reddit.com/r/programming/comments/dst56/today_i_learned_about_php_variable_variables/c12np38 > Wow. That's some scary stuff there. Yet, you can do the same sort of Stupid Language Tricks in Python and Perl as well. (LISP macros also come to mind.) PHP isn't alone in this regard. I think the problem in the article really hinges on the inconsistencies in interpretation of string constants, etc. 'Variable variables' aren't pure evil; they just provide a level of indirection that allows for fine-grained loss of control at runtime. They're also nastier to debug. Any language that has an 'eval' function or allows you to dynamically control the interpreter (or compiler) will give you this. > - Ron //jbaltz -- jerry b. altzman | jbaltz at altzman.com | www.jbaltz.com | twitter:@lorvax thank you for contributing to the heat death of the universe. From justin at justinhileman.info Thu Jan 30 15:16:09 2014 From: justin at justinhileman.info (justin) Date: Thu, 30 Jan 2014 15:16:09 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: <52EA87EE.7090805@altzman.com> References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> <52E93548.2000205@vnetworx.net> <52EA87EE.7090805@altzman.com> Message-ID: ? On Thu, Jan 30, 2014 at 12:12 PM, Jerry B. Altzman wrote: > fine-grained loss of control Awesome :) --j -------------- next part -------------- An HTML attachment was scrubbed... URL: From chsnyder at gmail.com Fri Jan 31 10:08:15 2014 From: chsnyder at gmail.com (Chris Snyder) Date: Fri, 31 Jan 2014 10:08:15 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: <52EA87EE.7090805@altzman.com> References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> <52E93548.2000205@vnetworx.net> <52EA87EE.7090805@altzman.com> Message-ID: On Thu, Jan 30, 2014 at 12:12 PM, Jerry B. Altzman wrote: > > 'Variable variables' aren't pure evil; they just provide a level of > indirection that allows for fine-grained loss of control at runtime. > Not only are they not evil, they're necessary for a lot of Don't Repeat Yourself optimizations. I use this pattern all the time: foreach( array('pages', 'posts', 'comments') AS $collection ) { ${$collection} = $model->load( $collection ); // do more stuff with ${$collection} here $template->assign( ${$collection}, $collection ); } It's a little bit harder to read until you get used to it, but because it's DRY it's much easier to manage over time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeff at jeffslutz.com Fri Jan 31 11:15:28 2014 From: jeff at jeffslutz.com (Jeff Slutz) Date: Fri, 31 Jan 2014 09:15:28 -0700 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> <52E93548.2000205@vnetworx.net> <52EA87EE.7090805@altzman.com> Message-ID: In the case you mention it's also about as easy to read/understand as it will ever be-- the contents of the array are right there. I find it gets trickier when the contents of that array are coming in from outside the function or method. Definitely still useful, but gets harder to track. -- Jeff Slutz JSLEUTH LLC 2105 N Fork Drive Lafayette, CO 80026 c. 970.443.9390 jeff at jeffslutz.com On Fri, Jan 31, 2014 at 8:08 AM, Chris Snyder wrote: > On Thu, Jan 30, 2014 at 12:12 PM, Jerry B. Altzman wrote: > >> >> 'Variable variables' aren't pure evil; they just provide a level of >> indirection that allows for fine-grained loss of control at runtime. >> > > Not only are they not evil, they're necessary for a lot of Don't Repeat > Yourself optimizations. > > I use this pattern all the time: > > foreach( array('pages', 'posts', 'comments') AS $collection ) { > ${$collection} = $model->load( $collection ); > // do more stuff with ${$collection} here > $template->assign( ${$collection}, $collection ); > } > > It's a little bit harder to read until you get used to it, but because > it's DRY it's much easier to manage over time. > > > _______________________________________________ > New York PHP User Group Community Talk Mailing List > http://lists.nyphp.org/mailman/listinfo/talk > > http://www.nyphp.org/show-participation > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ircmaxell at gmail.com Fri Jan 31 12:11:04 2014 From: ircmaxell at gmail.com (Anthony Ferrara) Date: Fri, 31 Jan 2014 12:11:04 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> <52E93548.2000205@vnetworx.net> <52EA87EE.7090805@altzman.com> Message-ID: Chris, On Fri, Jan 31, 2014 at 10:08 AM, Chris Snyder wrote: > On Thu, Jan 30, 2014 at 12:12 PM, Jerry B. Altzman wrote: > >> >> 'Variable variables' aren't pure evil; they just provide a level of >> indirection that allows for fine-grained loss of control at runtime. >> > > Not only are they not evil, they're necessary for a lot of Don't Repeat > Yourself optimizations. > Variable-variables as put here are not necessary in any situation. In general they are dangerous, and a potential security hole. If you MUST break down to native variables, use an array, and then extract() with the "overwrite" flag as false (to prevent potential issues). http://us2.php.net/extract > I use this pattern all the time: > > foreach( array('pages', 'posts', 'comments') AS $collection ) { > ${$collection} = $model->load( $collection ); > // do more stuff with ${$collection} here > $template->assign( ${$collection}, $collection ); > } > Yes, and that's significantly worse than: $container = array(); foreach( array('pages', 'posts', 'comments') AS $collection ) { $container[$collection] = $model->load( $collection ); // do more stuff with $container[$collection] here $template->assign( $container[$collection], $collection ); } It's even more clear, since it shows outright where the data is. You can tell instantly with any read where a variable was set. Using variable-variables, you have literally no idea until runtime (stepping through with a debugger) what area of code touches what variable. Without them (using arrays or objects) you can clearly see *what* container is being used, if not the specific element of it. It's a little bit harder to read until you get used to it, but because it's > DRY it's much easier to manage over time. > Many a great evil in programs have been done in the name of DRY. DRY != easier to manage. Clean coding with a focus on readability improve maintainability in the long term. Hacks to save a few characters of writing at the expense of cognitive load do not. In short, the only form of variable-variables that I believe should **ever** be used are variable object property/method references: $obj->$property = blah; $obj->$method(); Any other usage is simply mis-using variables where you should use a more appropriate data structure (like an array or object)... Anthony > _______________________________________________ > New York PHP User Group Community Talk Mailing List > http://lists.nyphp.org/mailman/listinfo/talk > > http://www.nyphp.org/show-participation > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbaltz at altzman.com Fri Jan 31 12:24:17 2014 From: jbaltz at altzman.com (Jerry B. Altzman) Date: Fri, 31 Jan 2014 12:24:17 -0500 Subject: [nycphp-talk] Variable composition: ${'foo'.$i} In-Reply-To: References: <52E6EF2D.5090609@vnetworx.net> <52E7019E.2050600@vnetworx.net> <52E93548.2000205@vnetworx.net> <52EA87EE.7090805@altzman.com> Message-ID: <52EBDC41.7040100@altzman.com> on 1/31/2014 12:11 PM Anthony Ferrara said the following: > Chris, > Not only are they not evil, they're necessary for a lot of Don't > Repeat Yourself optimizations. > Variable-variables as put here are not necessary in any situation. In > general they are dangerous, and a potential security hole. If you MUST > break down to native variables, use an array, and then extract() with > the "overwrite" flag as false (to prevent potential issues). > http://us2.php.net/extract Better said than I could have. Any time you have the program nondeterministically take code paths or branches, you introduce possibly subtle bugs that make reasoning about your program that much more difficult to do. Like I said, you can do the same badness in Python (by messing with internal object parts) or any other interpreted language (by messing with the interpreter). Any time you have effectively an 'eval' going on, you have the possibility of subtle logic errors, and security holes as well. > Yes, and that's significantly worse than: > $container = array(); > foreach( array('pages', 'posts', 'comments') AS $collection ) { > $container[$collection] = $model->load( $collection ); > // do more stuff with $container[$collection] here > $template->assign( $container[$collection], $collection ); > } > It's even more clear, since it shows outright where the data is. You can > tell instantly with any read where a variable was set. It's clearer, and doesn't pollute a namespace with spurious names created by mention. > Using variable-variables, you have literally no idea until runtime > (stepping through with a debugger) what area of code touches what variable. What's this PHP debugger you talk of? :-) > It's a little bit harder to read until you get used to it, but > because it's DRY it's much easier to manage over time. > Many a great evil in programs have been done in the name of DRY. DRY != > easier to manage. Clean coding with a focus on readability improve > maintainability in the long term. Hacks to save a few characters of > writing at the expense of cognitive load do not. Repeat after me: "Premature optimization is the root of all evil." Or better yet: "Code as if the person who has to support this code in 6 months is a homicidal psychopath who knows where you live." > In short, the only form of variable-variables that I believe should > **ever** be used are variable object property/method references: > $obj->$property = blah; > $obj->$method(); And even here, we get the same nondeterminism; $obj->$property isn't morally different from $obj[$property] Dynamic dispatch is hard! > Anthony //jbaltz -- jerry b. altzman | jbaltz at altzman.com | www.jbaltz.com | twitter:@lorvax thank you for contributing to the heat death of the universe.