From 49e56759c542e2a3ecb8632b666955b14ab6c6e7 Mon Sep 17 00:00:00 2001 From: hapo-tuanlh Date: Tue, 25 Apr 2023 08:46:11 +0700 Subject: [PATCH 1/2] create pull best practice --- docs/coding-practices/best-practices.md | 245 ++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 docs/coding-practices/best-practices.md diff --git a/docs/coding-practices/best-practices.md b/docs/coding-practices/best-practices.md new file mode 100644 index 0000000..86f94cb --- /dev/null +++ b/docs/coding-practices/best-practices.md @@ -0,0 +1,245 @@ +--- +sidebar_position: 3 +--- + +# Khởi tạo biến (Variable Initialization) + +## Biến nên được khởi tạo trước khi sử dụng + +````php + Date: Wed, 26 Apr 2023 08:29:28 +0700 Subject: [PATCH 2/2] add coding pratice for php --- docs/coding-practices/best-practices.md | 291 ++++++------------------ docs/coding-practices/function.md | 128 +++++++++++ docs/coding-practices/psr-1.md | 142 ++++++++++++ 3 files changed, 344 insertions(+), 217 deletions(-) create mode 100644 docs/coding-practices/function.md create mode 100644 docs/coding-practices/psr-1.md diff --git a/docs/coding-practices/best-practices.md b/docs/coding-practices/best-practices.md index 86f94cb..019f6f8 100644 --- a/docs/coding-practices/best-practices.md +++ b/docs/coding-practices/best-practices.md @@ -2,244 +2,101 @@ sidebar_position: 3 --- -# Khởi tạo biến (Variable Initialization) - -## Biến nên được khởi tạo trước khi sử dụng - -````php -, bạn có thể code là ) + +- Nguyên tắc 2: File code PHP sử dụng encode UTF-8 without BOM. + +- Nguyên tắc 3: File PHP NÊN dùng để khai báo các thành phần của PHP (class, function, const) và các hiệu ứng phụ (include, thiết lập init PHP), nhưng KHÔNG NÊN dùng cả hai trong một file. Để hiểu rõ hơn nguyên tắc này, bạn hãy xem ví dụ sau +````php +//bad + +\n"; + +// khai báo hàm +function foo() +{ + // function body +} + +//good +//file functions.php +\n"; +```` + +## Đối với khai báo namespace và class +- Nguyên tắc 1: namespace và class phải thuân theo chuẩn “autoload” PSR-0, PSR-4. + +Mỗi class được khai báo trên một file PHP riêng và có namespace tối thiểu một cấp, cấp đầu tiên là tên vendor (tên đơn vị phát hành) + +Tên class PHẢI được viết dạng ClassName thay vì classname, Classname, class_name hay Class_Name + +Từ PHP 5.3, PHẢI sử dụng namespace khi khai báo class. + +````php +//bad +