• Raul

    dynamic instantiation

  • Raul

  • Dynamic functions and dynamic instantiation are *not* the same as dynamic variables!

  • Igor

    Yes, Tudor, when using dynamic variables you can get bugs very hard to debug. But even if you have no bugs, it’s very tricky to refactor the code or even to understand it.

    I think that there are very very few cases when you really need dynamic variables. I even can bet that you can do the same thing using associative arrays. Btw, I suppose that internally PHP stores variables in associative arrays… that could explain all the logic…

  • I know this feature by the name “variable variables” but I guess dynamic variables makes sense too.

    I didn’t get what logic you hadn’t yet understood. The purpose of these dynamic variables?

  • Ionut: Yes! I don’t get it why did anyone strive so much to implement this feature. I find it quite useless. And yes, you are right, they are called “variable variables” – this is the official name 😛 I’ve changed the name above.

  • The only useful purpose that comes to mind is obfuscation. I’ve seen some nice examples of obfuscation using variable variables. But, you’re right about striving to implement such a thing. I don’t remember to have ever used them.

  • Tudor it’s not useless, the following example code creates variables from a form’s post fields:

  • Yes, I agree that there are thousands of nifty pieces of code out there – like the one you’ve posted – that make good use of this feature, but they are somewhat “artificial” and partially reserved for the more seasoned programmers. And that double dollar sign is very easy to miss. And while that code is clear to us, imagine how it would look to a junior programmer.

    You could also do it like this, without using variable variables:

    I agree it doesn’t have that Perl hacker style your script has, but it’s easier to understand.

  • Raul

    Mea culpa! ;))

  • Pingback: Strange PHP scoping :: Weird PHP programming | Tudor Barbu's professional blog()

Advertisment ad adsense adlogger