Skip to content

Use null coalescing operator instead of ternary operator #15021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions components/property_access.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ enable this feature by using :class:`Symfony\\Component\\PropertyAccess\\Propert
{
$property = lcfirst(substr($name, 3));
if ('get' === substr($name, 0, 3)) {
return isset($this->children[$property])
? $this->children[$property]
: null;
return $this->children[$property] ?? null;
} elseif ('set' === substr($name, 0, 3)) {
$value = 1 == count($args) ? $args[0] : null;
$this->children[$property] = $value;
Expand Down Expand Up @@ -334,9 +332,7 @@ see `Enable other Features`_::
{
$property = lcfirst(substr($name, 3));
if ('get' === substr($name, 0, 3)) {
return isset($this->children[$property])
? $this->children[$property]
: null;
return $this->children[$property] ?? null;
} elseif ('set' === substr($name, 0, 3)) {
$value = 1 == count($args) ? $args[0] : null;
$this->children[$property] = $value;
Expand Down
4 changes: 2 additions & 2 deletions create_framework/http_foundation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ First, if the ``name`` query parameter is not defined in the URL query string,
you will get a PHP warning; so let's fix it::

// framework/index.php
$name = isset($_GET['name']) ? $_GET['name'] : 'World';
$name = $_GET['name'] ?? 'World';

printf('Hello %s', $name);

Then, this *application is not secure*. Can you believe it? Even this simple
snippet of PHP code is vulnerable to one of the most widespread Internet
security issue, XSS (Cross-Site Scripting). Here is a more secure version::

$name = isset($_GET['name']) ? $_GET['name'] : 'World';
$name = $_GET['name'] ?? 'World';

header('Content-Type: text/html; charset=utf-8');

Expand Down
2 changes: 1 addition & 1 deletion frontend/custom_version_strategy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ version string::
$this->hashes = $this->loadManifest();
}

return isset($this->hashes[$path]) ? $this->hashes[$path] : '';
return $this->hashes[$path] ?? '';
}

public function applyVersion($path)
Expand Down