Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name variables in Laravel [closed]

Refer: How you name variables in Laravel & PHP.

$firstName or $first_name?

$userid or $userId or $user_id?

like image 889
Oc Chuoj Dau Avatar asked Jun 17 '13 04:06

Oc Chuoj Dau


2 Answers

PSR-1 Coding Standards have this to say:

Whatever naming convention is used SHOULD be applied consistently within a reasonable scope. That scope may be vendor-level, package-level, class-level, or method-level.

Personally I use mixedCase for properties and underscored separated for variables defined in a function, method or in global scope.

The important thing is to use it consistently so that you will be able to readily tell if a variable is being misused (i.e. I know if I see a camel cased variable without an object operator I know it is an error).

Larvel 4's coding guidelines state that they adhere to PSR-1 with no mention of the representation of variables.

like image 169
Orangepill Avatar answered Nov 01 '22 18:11

Orangepill


Laravel 3: $first_name
Laravel 4: $firstName

Why? Cause you following the framework convention makes your code easier too read for other developers which join the project later.

Thats not my personal prefer. Thats what the crowd hopefully do. :)

like image 39
skdo Avatar answered Nov 01 '22 18:11

skdo