• Published:August 21st, 2013
  • Category:Lavarel4, php
  • 4 comments

Laravel supports the PHP Framework Interop Group naming conventions. You can find them on the PHP-FIG website.

In short:

  • Generally database columns are snake_case but property names are camelCase. Eloquent is able to do the conversion automatically.
  • Class names must be declared in StudlyCaps.
  • Class constants must be declared in all upper case with underscore separators.
  • Method names must be declared in camelCase. (this used to be snake_case in L3)
  • Property names and function arguments have generally not a specific rule, but must be written according to the package. The Laravel doc about the convention doesn’t give more information about property names.. The only rule is: always use the same. I would suggest camelCase.
  • Function names are camelCase. (however the Official PHP coding standards advices snake_case).
  • For Variables names I would suggest camelCase, however snake_case is advised by the Official PHP coding standards, in contrast with the recommandations from the Zend Framework, which explicitly forbids underscores. Variables are not mentioned in the PHP Framework Interop Group and I can’t find any examples in the base Laravel framework because all variable names are single words.

I’d like to add that naming conventions are a controversial subject, because a lot of standard PHP functions don’t follow any naming convention.

« Previous Page

Wordpress.org clearPaper by CreativeBits.it Copyright © 2012-2019 Robin Brackez. All rights reserved. By visiting this site you agree to accept cookies that are purely used to check how many visitors I have. Theme by: creativebits. Custom adaptations by Robin Brackez.