NotionCommotion Posted August 21, 2016 Share Posted August 21, 2016 I am currently inconsistent on my naming convention, and would like to better standardize. If starting from scratch, what would you recommend for the following for PHP? I included what I think are the best optons below, but if it should be something totally different, please advise. While outside of the scope of this forum, recommendations for JavaScript would also be appreciated. Thank you Classes: PascalCase Name Spaces: PascalCase or camelCase? Methods: camelCase or lower_case? Properties: camelCase or lower_case? Functions: camelCase or lower_case? Variables: camelCase or lower_case? Arrays: camelCase or lower_case? Array Elements: camelCase or lower_case? Anything I am missing? Also, for each, should they be plural or singular? Quote Link to comment https://forums.phpfreaks.com/topic/301956-recommended-naming-convention/ Share on other sites More sharing options...
NotionCommotion Posted August 21, 2016 Author Share Posted August 21, 2016 Also, what about filenames for classes and normal files? Quote Link to comment https://forums.phpfreaks.com/topic/301956-recommended-naming-convention/#findComment-1536397 Share on other sites More sharing options...
ignace Posted August 21, 2016 Share Posted August 21, 2016 http://www.php-fig.org/ Quote Link to comment https://forums.phpfreaks.com/topic/301956-recommended-naming-convention/#findComment-1536398 Share on other sites More sharing options...
Jacques1 Posted August 21, 2016 Share Posted August 21, 2016 PSR-1 Basic Coding Standard Properties: camelCase or lower_case? Variables: camelCase or lower_case? There are no explicit rules, but when you already use camelCase for methods and functions (as the standard recommends), it makes sense to use the same for variables and properties. Arrays: camelCase or lower_case? Array Elements: camelCase or lower_case? What? Also, for each, should they be plural or singular? That definitely depends on the concrete case. Quote Link to comment https://forums.phpfreaks.com/topic/301956-recommended-naming-convention/#findComment-1536399 Share on other sites More sharing options...
Jacques1 Posted August 21, 2016 Share Posted August 21, 2016 Regarding JavaScript: Crockford's Code Conventions for the JavaScript Programming Language I don't think it's explicitly mentioned, but most JavaScript programmers use camelCase (functions, methods, variables) and PascalCase (constructors). Quote Link to comment https://forums.phpfreaks.com/topic/301956-recommended-naming-convention/#findComment-1536400 Share on other sites More sharing options...
NotionCommotion Posted August 21, 2016 Author Share Posted August 21, 2016 Thank you Ignace and Jacques1. PSR-1 is a good reference. Arrays: camelCase or lower_case? Array Elements: camelCase or lower_case? What? My bad, an array is just a variable. Regarding array elements: $myArr['myElement'], what should "myElement" be? Also, if my class name is MyClass, should the filename be MyClass.php or myclass.php? Quote Link to comment https://forums.phpfreaks.com/topic/301956-recommended-naming-convention/#findComment-1536401 Share on other sites More sharing options...
Jacques1 Posted August 21, 2016 Share Posted August 21, 2016 (edited) Regarding array elements: $myArr['myElement'], what should "myElement" be? I'm not aware of any rules for array keys. I tend to use underscores. Also, if my class name is MyClass, should the filename be MyClass.php or myclass.php? PSR-4 (the filename and class name must match) Edited August 21, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301956-recommended-naming-convention/#findComment-1536402 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.