variables - is it accepted to name a php varible like $_xxx? -


i'm building site , included settings file named "settings.php", think it's cool register global var name: $_settings array of site settings (db_name, db_pass....etc) so:

<?php     $_settings = array();     $_settings['db_hostname']= 'localhost';     $_settings['db_name'] = 'db_test';     $_settings['db_username'] = 'db_user';     $_settings['db_password'] = 'p422w0rd';  ?> 

and access settings on sub pages... accessing $_settings...

this code works fine, i'm curious acceptable among php programmers community name own variables $_ ? or code considered bad design?

thanks

you can it, wouldn't recommend it, since superglobal variables have pattern/prefix e.g. $_server, $_session, $_get maybe bit confusing.

but according manual. technical can it:

a valid variable name starts letter or underscore, followed number of letters, numbers, or underscores. regular expression, expressed thus: '[a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff]*'

at end it's personal preference do.


Popular posts from this blog