Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a preferred way to name variables in PHP? [closed]

Tags:

variables

php

I am fairly new to PHP and I was wondering if there was a standard convention to name php variables. I'm used to using camel case when naming variables, but I see a lot of underscores in PHP examples.

Is there a standard naming convention that most people use for PHP?

$buildingHeight OR $building_height

like image 773
lonewookie Avatar asked Dec 31 '13 14:12

lonewookie


1 Answers

It is really all about your preference in the case you mentioned. I prefer using underscore because it helps me read the variables better when scanning through the code, but ultimately it's up to you.

Other important things to note about PHP variables:

  • Must start with a letter or underscore (_).

  • May only be composed of alpha-numeric characters and underscores a-z, A-Z, 0-9, or _ .

I hope this helps!

like image 96
Mussser Avatar answered Sep 30 '22 15:09

Mussser