From a23c4bfe865951b252552a0dbe87ba4c658fb03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Mour=C3=A3o?= Date: Tue, 19 Nov 2019 20:18:51 -0300 Subject: [PATCH 1/2] Adding question mark when nullable value is declared --- .../backward-compatible-development/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); From ab590c7e1d069a1f5813099b73344efc6ca3833e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Mour=C3=A3o?= Date: Tue, 19 Nov 2019 20:25:46 -0300 Subject: [PATCH 2/2] Adding nullable param question mark in v2.2 --- .../backward-compatible-development/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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);