Differences
This shows you the differences between two versions of the page.
| |
rfc:check_and_set [2018/07/06 13:25] – created malukenho | rfc:check_and_set [2018/07/06 13:30] (current) – malukenho |
---|
`<nowiki>$x += 3</nowiki>`. | `<nowiki>$x += 3</nowiki>`. |
| |
With PHP being a web focused language, the `?:` operator is often used to check something's existence like `<nowiki>$this->obj = $obj ?: new \stdClass;</nowiki>` However, because | With PHP being a web focused language, the `?:` ternary operator is often used to check something's existence like `<nowiki>$this->obj = $obj ?: new \stdClass;</nowiki>` However, because |
variable names are often much longer than `<nowiki>$username</nowiki>`, the use of `<nowiki>?:</nowiki>` for self assignment creates repeated code, like: | variable names are often much longer than `<nowiki>$username</nowiki>`, the use of `<nowiki>?:</nowiki>` for self assignment creates repeated code, like: |
| |
</code> | </code> |
| |
It is also intuitive to use combined assignment operator null coalesce checking for self assignment. | It is also intuitive to use combined assignment operator null ternary checking for self assignment. |
| |
# Proposal | # Proposal |
| |
Despite `<nowiki>?:</nowiki>` operator being a comparison operator, coalesce equal or `<nowiki>?=</nowiki>` operator is an assignment operator. If the left parameter is null, assigns the value of the right paramater to the left one. If the value is not null, nothing is made. | Despite `<nowiki>?:</nowiki>` operator being a comparison operator, ternary equal or `<nowiki>?=</nowiki>` operator is an assignment operator. If the left parameter is null, assigns the value of the right paramater to the left one. If the value is not null, nothing is made. |
| |
| |