3

Possible Duplicate:
What are “#” properties?

This one's more out of curiosity than anything.

If you look at the Form API Reference, you can see that all properties have number signs/hash marks (#) at the start of the key.

Ermahgerd, lerk at erm errl!

My question is, why is it like this? Why bother having these hash marks in front of property names, other than "That's the convention somebody somewhere decided", and to occasionally cause people grief when they forget to add one?

Quite curious. Thanks!

2
  • Sorry for the very quick closure but I remember this one coming up a while ago :)
    – Clive
    Nov 27 '12 at 17:14
  • @Clive No worries, hadn't seen that question. Thanks for linking it!
    – aendra
    Nov 28 '12 at 0:04
1

It's a convention to add a hash tag to properties that correspond to a setting rather than an element. This is done to avoid namespace collisions.

1
  • Accepting; succinct and accurate.
    – aendra
    Jan 1 '14 at 1:22
2

If you don't add a hashmark you're not setting that property, but are instead defining another level of a render array element. Consider this example:

$form['your_name'] = array(
  '#type' => 'textfield',
  '#title' => 'Your Name',
  'title' => array( // I am an entirely new element, whose key is "title".
    '#type' => 'textfield',
    '#title' => 'Your Title',
    '#description' => 'Example: Sir, Mr, Bossman, Chieftan',
  ),
);

This example is silly, but it should describe why a hashmark is used to set a property. If your question is really "why use a hashmark instead of an exclamation point, an ampersand, or some other random character?", well, I don't know. I've seen the hash symbol used to define properties in other languages and APIs.

Not the answer you're looking for? Browse other questions tagged or ask your own question.