Uppercase for variable on PHP, good or not? -


is recommended write code in uppercase ?

like:

$variable = "johndoe";  require_once 'class.username.php';  $_username = new username(); $_username->add($variable); 

thanks.

you free use whatever case want.

historically there have been several conventions. preferred uppercase, lowercase, , yet preferred mixed case. used depended on how wrote html, , background came (some programming languages encouraged/required use uppercase, instance, , because php not picky case use easy continue using knew).

now-a-days there couple conventions. following see when reading other people's code:

most people use lowercase variable , function names:

$name = "some name"; function age(person $person) {     return $person->age; } 

as names contain more 1 word there tends 2 camps: prefer camelcase, , prefer under_score:

$personname = "some name"; function getage(person $person) {     return $person->age; } // or... $person_name = "some name"; function get_age(person $person) {     return $person->age; } 

for classes/interfaces/etc. people use same convention variables , functions, uppercasing first character. done in order make easier differentiate them other things function names (i.e. functions start lowercase, classes/interfaces/etc. start uppercase). multiple words in camelcase or in under_score.

class names formatted in such way facilitate autoloading. using underscores way mirror underlying folder structure (_ becomes /, i.e. under/score). camelcase can used in same manner putting folder separator before second, , later, capitalised letters (i.e. camel/case).

with namespaces becoming more , more popular making class name analogous file path has become less , less necessary (the namespace has largely taken on role). because makes kind of sense, , because autoloading standards/conventions still around, still see it, though.

class person {} class computerprogrammer extends person {} // or... class computer_programmer extends person {} 

for constants people use uppercase. make constants distinct variables/function/etc. convention comes c language, php closely related to.

define("db_pass", "pa5sw0rd"); 

related constants, language constant such booleans , null in either lowercase or uppercase:

true true false false null null 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -