Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit a3967a2

Browse files
authored
Merge pull request #6033 from rodrigowebjump/patch-7
Adding question mark when nullable value is declared
2 parents f381a1f + ab590c7 commit a3967a2

File tree

2 files changed

+6
-2
lines changed
  • guides
    • v2.2/contributor-guide/backward-compatible-development
    • v2.3/contributor-guide/backward-compatible-development

2 files changed

+6
-2
lines changed

guides/v2.2/contributor-guide/backward-compatible-development/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Add a new optional parameter to the constructor at the end of the arguments list
122122

123123
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()`.
124124

125+
Prefix the type name with a question mark when declaring a parameter with a `null` default value.
126+
125127
{% collapsible Example Code %}
126128

127129
```php
@@ -134,7 +136,7 @@ class ExistingClass
134136
\Old\Dependency\Interface $oldDependency,
135137
$oldRequiredConstructorParameter,
136138
$oldOptionalConstructorParameter = null,
137-
\New\Dependency\Interface $newDependency = null
139+
?\New\Dependency\Interface $newDependency = null
138140
) {
139141
...
140142
$this->newDependency = $newDependency ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\New\Dependency\Interface::class);

guides/v2.3/contributor-guide/backward-compatible-development/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Add a new optional parameter to the constructor at the end of the arguments list
128128

129129
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()`.
130130

131+
Prefix the type name with a question mark when declaring a parameter with a `null` default value.
132+
131133
{% collapsible Example Code %}
132134

133135
```php
@@ -140,7 +142,7 @@ class ExistingClass
140142
\Old\Dependency\Interface $oldDependency,
141143
$oldRequiredConstructorParameter,
142144
$oldOptionalConstructorParameter = null,
143-
\New\Dependency\Interface $newDependency = null
145+
?\New\Dependency\Interface $newDependency = null
144146
) {
145147
...
146148
$this->newDependency = $newDependency ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\New\Dependency\Interface::class);

0 commit comments

Comments
 (0)