diff --git a/guides/v2.2/contributor-guide/backward-compatible-development/index.md b/guides/v2.2/contributor-guide/backward-compatible-development/index.md index be52f4eef3c..7101b896071 100644 --- a/guides/v2.2/contributor-guide/backward-compatible-development/index.md +++ b/guides/v2.2/contributor-guide/backward-compatible-development/index.md @@ -122,6 +122,8 @@ Add a new optional parameter to the constructor at the end of the arguments list In the constructor body, if the new dependency is not provided (i.e. the value of the introduced argument is `null`), fetch the dependency using `Magento\Framework\App\ObjectManager::getInstance()`. +Prefix the type name with a question mark when declaring a parameter with a `null` default value. + {% collapsible Example Code %} ```php @@ -134,7 +136,7 @@ class ExistingClass \Old\Dependency\Interface $oldDependency, $oldRequiredConstructorParameter, $oldOptionalConstructorParameter = null, - \New\Dependency\Interface $newDependency = null + ?\New\Dependency\Interface $newDependency = null ) { ... $this->newDependency = $newDependency ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\New\Dependency\Interface::class); diff --git a/guides/v2.3/contributor-guide/backward-compatible-development/index.md b/guides/v2.3/contributor-guide/backward-compatible-development/index.md index fc7263ad09d..c8e69937c78 100644 --- a/guides/v2.3/contributor-guide/backward-compatible-development/index.md +++ b/guides/v2.3/contributor-guide/backward-compatible-development/index.md @@ -128,6 +128,8 @@ Add a new optional parameter to the constructor at the end of the arguments list In the constructor body, if the new dependency is not provided (i.e. the value of the introduced argument is `null`), fetch the dependency using `Magento\Framework\App\ObjectManager::getInstance()`. +Prefix the type name with a question mark when declaring a parameter with a `null` default value. + {% collapsible Example Code %} ```php @@ -140,7 +142,7 @@ class ExistingClass \Old\Dependency\Interface $oldDependency, $oldRequiredConstructorParameter, $oldOptionalConstructorParameter = null, - \New\Dependency\Interface $newDependency = null + ?\New\Dependency\Interface $newDependency = null ) { ... $this->newDependency = $newDependency ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\New\Dependency\Interface::class);