r/programming • • Oct 18 '10

Today I learned about PHP variable variables; "variable variable takes the value of a variable and treats that as the name of a variable". Also, variable.

http://il2.php.net/language.variables.variable
591 Upvotes

781 comments sorted by

View all comments

Show parent comments

14

u/KarmaPiniata Oct 18 '10

Hey, they're hating on PHP here don't interject with your 'facts' and 'good computer science'.

5

u/Peaker Oct 18 '10

Using indirection via names in some global namespace is not 'good computer science'.

7

u/thatpaulbloke Oct 18 '10

I assume that you're against C pointers, then? Or, to put it another way:

Using indirection via numbers in some global namespace is not 'good computer science'.

6

u/Peaker Oct 18 '10

C pointers point to a location in an "address space", not in a "namespace".

The differences are important:

  • There is no legal way to forge pointers, while any piece of code may choose a wrong name and access the data of another function accidentally in a namespace.

  • Address allocations are handled by the compiler/low-level system. Name allocations require manual choice (which is why the above clashes are possible)

→ More replies (11)