From 530e4d582a4aa8e11ee2c26bb78e00330fb81f3a Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 16:59:36 +1200 Subject: [PATCH] DOC Do not use self --- .../05_Coding_Conventions/01_PHP_Coding_Conventions.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/en/10_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md b/en/10_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md index 7ba79b871..ebbd41283 100644 --- a/en/10_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md +++ b/en/10_Contributing/05_Coding_Conventions/01_PHP_Coding_Conventions.md @@ -172,3 +172,6 @@ PHPDocs are not only useful when looking at the source code, but are also used i - Prefer the identical `===` operator over the equality `==` operator for comparisons. - If you directly reference a third-party dependency in code, then ensure the dependency is required in the module's `composer.json` file. - Avoid hardcoding values when there is a method available to dynamically get a value, for example use [`DataObjectSchema::tableName()`](api:SilverStripe\ORM\DataObjectSchema::tableName()) to get the table name for a `DataObject` model rather than hard coding it. +- Do not use the `self` keyword, e.g. `self::myMethod()` instead use the short-name of the current class e.g. `MyClass::myMethod()` which is functionally equivalent. This avoids a specific class of bug that is introduced when using late static binding downstream from `self`. + - The one exception to this rule is traits as there is no way to know the class the trait is applied to. + - Note that use of the `static` keyword is perfectly OK.