PHP string constants overuse?

Advantages

  • consequences of misspelling constant should trigger an E_NOTICE 'Use of undefined constant', whereas misspelling the string literal would not offer such an early warning.
  • if followed to its logical conclusion, any remaining string literals in the code should be natural language, and thus the task of identifying strings to be wrapped in an internationalization translation layer is made a little easier.

Disadvantages

  • requires you define all constants whether you need them or not. Not likely to be your performance bottleneck unless you're defining thousands of them though!

There is a valid argument for using constants like that.

If you accidentally do something like:

$router->map('/some_url', array('moduel' => 'some_module', 'action' => 'some_action'));

it will fail in some undefined way (note the misspelled "moduel").

If you make a spelling mistake or typo when a constant is involved, PHP emits a Notice, and you catch it right away.

How often that actually saves you is a matter for debate. Personally, I usually don't think it's worth the trouble.