{"id":548,"date":"2026-08-05T21:52:58","date_gmt":"2026-08-05T14:52:58","guid":{"rendered":"https:\/\/phpha.ru\/?p=548"},"modified":"2026-08-05T22:03:06","modified_gmt":"2026-08-05T15:03:06","slug":"%d0%a0%d0%b0%d0%b7%d0%bd%d0%b8%d1%86%d0%b0-%d0%bc%d0%b5%d0%b6%d0%b4%d1%83-%d0%b8","status":"publish","type":"post","link":"https:\/\/phpha.ru\/?p=548","title":{"rendered":"\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443\u00a0??\u00a0\u0438\u00a0?:"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u2014 \u0432\u00a0<strong>\u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438<\/strong>. <code>\"?:\"<\/code>\u00a0&#8212; \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 . &#171;<code>??\"<\/code>\u00a0&#8212; \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 null.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 ?:<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">$result = $value ?: $default;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u042d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0442<strong>\u00a0<code>$result = $value ? $value : $default;<\/code><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0427\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f&nbsp;<code>false<\/code>&nbsp;(falsy):<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>null<\/code><\/li>\n\n\n\n<li><code>false<\/code><\/li>\n\n\n\n<li><code>0<\/code>\u00a0(\u043d\u043e\u043b\u044c)<\/li>\n\n\n\n<li><code>\"\"<\/code>\u00a0(\u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430)<\/li>\n\n\n\n<li><code>\"0\"<\/code>\u00a0(\u0441\u0442\u0440\u043e\u043a\u0430 \u0441 \u043d\u0443\u043b\u0435\u043c)<\/li>\n\n\n\n<li><code>[]<\/code>\u00a0(\u043f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 ??<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">$result = $value ?? $default;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u042d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0442<strong>\u00a0<code>$result = isset($value) ? $value : $default;<\/code><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430&nbsp;<strong><code>null<\/code><\/strong>&nbsp;(\u0438 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043a\u0438).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u041e\u0442\u043a\u0443\u0434\u0430 \u044d\u0442\u043e \u0432\u0437\u044f\u043b\u043e\u0441\u044c<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>?:<\/code>\u00a0(\u0442\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440)<\/strong>\u00a0\u2014 \u0435\u0441\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u043e \u0432\u0441\u0435\u0445 C-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 (C, C++, Java, C#). \u041f\u0440\u043e\u0441\u0442\u043e PHP \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u0447\u0430\u0441\u0442\u044c (<code>x ?: y<\/code>). \u042d\u0442\u043e \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0432\u00a0<strong>PHP 5.3<\/strong>.<\/li>\n\n\n\n<li><strong><code>??<\/code>\u00a0(Null coalescing)<\/strong>\u00a0\u2014 \u0431\u044b\u043b \u0443\u043a\u0440\u0430\u0434\u0435\u043d (\u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d) \u0438\u0437 \u043c\u0438\u0440\u0430\u00a0<strong>C#<\/strong>\u00a0(\u0433\u0434\u0435 \u043e\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f null-coalescing operator). \u0412 PHP \u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432\u00a0<strong>PHP 7<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0443\u0441\u0442\u0430\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c\u00a0<code>isset($_GET['key']) ? $_GET['key'] : 'default'<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u043b\u0438 \u0442\u043e\u043d \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u041e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0414\u0410<\/strong>, \u043d\u043e \u0441 \u043e\u0433\u043e\u0432\u043e\u0440\u043a\u0430\u043c\u0438.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u042d\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f&nbsp;<strong>\u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c<\/strong>&nbsp;\u043a\u043e\u0434\u043e\u043c. PHP-\u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 7.4+) \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442&nbsp;<code>??<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0435\u043d \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0442\u043e\u043d\u0430 (Best Practices):<\/strong><\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0<code>??<\/code>\u00a0\u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 (<code>$_GET<\/code>,\u00a0<code>$_POST<\/code>,\u00a0<code>$_SESSION<\/code>)<\/strong>. \u042d\u0442\u043e \u043b\u0443\u0447\u0448\u0438\u0439 \u0434\u0440\u0443\u0433 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430.php$name = $_POST[&#8216;name&#8217;] ?? &#8216;\u0413\u043e\u0441\u0442\u044c&#8217;; \/\/ \u0411\u0435\u0437 \u043e\u0448\u0438\u0431\u043a\u0438, \u0435\u0441\u043b\u0438 \u043a\u043b\u044e\u0447\u0430 \u043d\u0435\u0442<\/li>\n\n\n\n<li><strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0<code>?:<\/code>\u00a0\u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e<\/strong>. \u041e\u043d \u0445\u043e\u0440\u043e\u0448, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e\u00a0<code>0<\/code>,\u00a0<code>\"\"<\/code>\u00a0\u0438\u00a0<code>false<\/code>\u00a0\u0434\u043b\u044f \u0432\u0430\u0441 \u2014 \u044d\u0442\u043e &#171;\u043f\u043b\u043e\u0445\u043e&#187;.php\/\/ \u041f\u043b\u043e\u0445\u043e (\u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u043d\u0430 0) $count = getCount() ?: 10; \/\/ \u0425\u043e\u0440\u043e\u0448\u043e (\u0435\u0441\u043b\u0438 getCount() \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 -1 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435) $count = getCount() ?: 10; \/\/ -1 \u044d\u0442\u043e true, \u043e\u043a.<\/li>\n\n\n\n<li><strong>\u0426\u0435\u043f\u043e\u0447\u043a\u0438 (<code>??<\/code>) \u2014 \u044d\u0442\u043e \u0441\u0443\u043f\u0435\u0440-\u0441\u0438\u043b\u0430<\/strong>\u00a0(\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0441 PHP 7+):php\/\/ \u0418\u0449\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 null $user = $_GET[&#8216;user&#8217;] ?? $_POST[&#8216;user&#8217;] ?? $_SESSION[&#8216;user&#8217;] ?? &#8216;\u0410\u043d\u043e\u043d\u0438\u043c&#8217;;<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u0421\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0431\u043e\u043d\u0443\u0441: \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440&nbsp;<code>?-&gt;<\/code>&nbsp;(Nullsafe)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u0420\u0430\u0437 \u0443\u0436 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e PHP 8, \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440&nbsp;<strong><code>?-&gt;<\/code><\/strong>&nbsp;(nullsafe operator).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ \u0411\u0435\u0437 \u043d\u0435\u0433\u043e (\u0435\u0441\u043b\u0438 $user = null, \u0431\u0443\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430)\n$city = $user-&gt;getProfile()-&gt;getAddress()-&gt;city;\n\n\/\/ \u0421 \u043d\u0438\u043c (\u0435\u0441\u043b\u0438 $user = null, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u0440\u043d\u0435\u0442 null, \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442)\n$city = $user?-&gt;getProfile()?-&gt;getAddress()?-&gt;city ?? '\u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437&nbsp;<code>if (!is_null(...))<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0418\u0442\u043e\u0433:<\/strong>\u00a0\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0<code>??<\/code>\u00a0\u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437\u0432\u043d\u0435 (\u0444\u043e\u0440\u043c\u044b, \u0411\u0414),\u00a0<code>?:<\/code>\u00a0\u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0438 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0441\u0442\u044b\u043c \u0438 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u043c. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u2014 \u0432\u00a0\u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438. &#171;?:&#187;\u00a0&#8212; \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 . &#171;??&#187;\u00a0&#8212; \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 null.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-548","post","type-post","status-publish","format-standard","hentry","category-base"],"_links":{"self":[{"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/posts\/548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpha.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=548"}],"version-history":[{"count":2,"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/posts\/548\/revisions"}],"predecessor-version":[{"id":550,"href":"https:\/\/phpha.ru\/index.php?rest_route=\/wp\/v2\/posts\/548\/revisions\/550"}],"wp:attachment":[{"href":"https:\/\/phpha.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpha.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpha.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}