From 9529fde72b4040bc94f399ae1227336c311dfc7b Mon Sep 17 00:00:00 2001 From: Christoph Daum Date: Tue, 10 Sep 2024 15:36:57 +0200 Subject: [PATCH 1/6] Update php.md Fixed: require/import => require/include --- wordpress-coding-standards/php.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index 9cbb528..80fbc52 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -605,7 +605,7 @@ Group `use` statements are available from PHP 7.0, and trailing commas in group [/alert] [info] -Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load whatever is being imported. You'll either need to set up autoloading or load the file containing the class/function/constant using a `require/import` statement, for the imported constructs to be loaded when used. +Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load whatever is being imported. You'll either need to set up autoloading or load the file containing the class/function/constant using a `require/include` statement, for the imported constructs to be loaded when used. [/info] **Note about WordPress Core usage** From eccc5b64bbd5487d8be95bab2abd5af308a680c0 Mon Sep 17 00:00:00 2001 From: Christoph Daum Date: Tue, 10 Sep 2024 15:59:56 +0200 Subject: [PATCH 2/6] Update php.md Per @jrfnl's suggestion, made clear that autoloading only applies to classes. --- wordpress-coding-standards/php.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index 80fbc52..bfa9694 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -605,7 +605,7 @@ Group `use` statements are available from PHP 7.0, and trailing commas in group [/alert] [info] -Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load whatever is being imported. You'll either need to set up autoloading or load the file containing the class/function/constant using a `require/include` statement, for the imported constructs to be loaded when used. +Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include` statement, for the imported classes to be loaded when used.Autoloading is only applicable to classes; for functions and constants, you must always use `require` or `include`. [/info] **Note about WordPress Core usage** From 5508008bcb845f76946c6cd8b265fda96a53bc9f Mon Sep 17 00:00:00 2001 From: Christoph Daum Date: Tue, 10 Sep 2024 16:01:42 +0200 Subject: [PATCH 3/6] Update php.md Fixed missing space. --- wordpress-coding-standards/php.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index bfa9694..0cbdcc9 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -605,7 +605,7 @@ Group `use` statements are available from PHP 7.0, and trailing commas in group [/alert] [info] -Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include` statement, for the imported classes to be loaded when used.Autoloading is only applicable to classes; for functions and constants, you must always use `require` or `include`. +Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `require` or `include`. [/info] **Note about WordPress Core usage** From 9c97d9b9eae7e6a30e2e91ee69721e8fb92629f6 Mon Sep 17 00:00:00 2001 From: Christoph Daum Date: Wed, 11 Sep 2024 09:22:25 +0200 Subject: [PATCH 4/6] Update php.md Applied suggestion from code review by @jrfnl --- wordpress-coding-standards/php.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index 0cbdcc9..3e286a2 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -605,7 +605,7 @@ Group `use` statements are available from PHP 7.0, and trailing commas in group [/alert] [info] -Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `require` or `include`. +Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `require[_once]` or `include[_once]`. [/info] **Note about WordPress Core usage** From c9ea3cad6470380822f1928e037276a88ceb8eae Mon Sep 17 00:00:00 2001 From: Christoph Daum Date: Fri, 13 Sep 2024 13:21:53 +0200 Subject: [PATCH 5/6] Update php.md Further code review feedback. Changed order to alphabetikal order: include, require. To be consistent with Lines 81-83 (Writing include/require statements) and --- wordpress-coding-standards/php.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index 3e286a2..aacf161 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -605,7 +605,7 @@ Group `use` statements are available from PHP 7.0, and trailing commas in group [/alert] [info] -Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `require[_once]` or `include[_once]`. +Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using `include[_once]` or `require[_once]` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `include[_once]` or `require[_once]`. [/info] **Note about WordPress Core usage** From e520d9e02f1761b3ade93c5f0753882335fa5775 Mon Sep 17 00:00:00 2001 From: Christoph Daum Date: Mon, 23 Sep 2024 08:20:09 +0200 Subject: [PATCH 6/6] Update php.md Switched from alphabetical order, to recommendation order. --- wordpress-coding-standards/php.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wordpress-coding-standards/php.md b/wordpress-coding-standards/php.md index aacf161..aafa2b0 100644 --- a/wordpress-coding-standards/php.md +++ b/wordpress-coding-standards/php.md @@ -78,11 +78,11 @@ echo "text with a ' single quote"; Text that goes into HTML or XML attributes should be escaped so that single or double quotes do not end the attribute value and invalidate the HTML, causing a security issue. See [Data Validation](https://developer.wordpress.org/plugins/security/data-validation/) in the Plugin Handbook for further details. -### Writing include/require statements +### Writing require/include statements -Because `include[_once]` and `require[_once]` are language constructs, they do not need parentheses around the path, so those shouldn't be used. There should only be one space between the path and the include/require keywords. +Because `require[_once]` and `include[_once]` are language constructs, they do not need parentheses around the path, so those shouldn't be used. There should only be one space between the path and the require/include keywords. -It is _strongly recommended_ to use `require[_once]` for unconditional includes. When using `include[_once]`, PHP will throw a warning when the file is not found but will continue execution, which will almost certainly lead to other errors/warnings/notices being thrown if your application depends on the file loaded, potentially leading to security leaks. For that reason, `require[_once]` is generally the better choice as it will throw a `Fatal Error` if the file cannot be found. +It is _strongly recommended_ to use `require[_once]` for unconditional includes. When using `include[_once]`, PHP will throw a warning when the file is not found but will continue execution, which will almost certainly lead to other errors/warnings/notices being thrown if your application depends on the file loaded, potentially leading to security leaks, or result in silent malfunctions which are hard to track down. For that reason, `require[_once]` is generally the better choice as it will throw a `Fatal Error` if the file cannot be found. ```php // Correct. @@ -605,7 +605,7 @@ Group `use` statements are available from PHP 7.0, and trailing commas in group [/alert] [info] -Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using `include[_once]` or `require[_once]` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `include[_once]` or `require[_once]`. +Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using `require[_once]` or `include[_once]` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `require[_once]` or `include[_once]`. [/info] **Note about WordPress Core usage**