{"id":772,"date":"2020-01-09T17:04:33","date_gmt":"2020-01-09T17:04:33","guid":{"rendered":"https:\/\/sdf-docs.mansystems.com\/docs\/acr-rules\/reliability\/check-for-empty-string-should-be-done-properly\/"},"modified":"2020-03-20T08:44:58","modified_gmt":"2020-03-20T08:44:58","slug":"emptystringcheck","status":"publish","type":"docs","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/reliability\/emptystringcheck","title":{"rendered":"Check for empty string should be done properly"},"content":{"rendered":"\n<p style=\"text-align:center\">Introduced in version: 1.3 (29 Jan 2020)<\/p>\n\n\n\n<p>&#8216;This is very likely a bug and should be changed. There are only two correct ways to check for empty string<\/p>\n\n\n\n<p><strong>Noncompliant example:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>$Str = empty and trim($Str) != ''<\/code> &#8211;  equal used instead of not equal or other way around<\/li><li> <code>$Str = empty and trim($Str) = ''<\/code> &#8211; <code>and <\/code>is used instead of <code>or <\/code>or other way around<\/li><li> <code>trim($Str) != ''and $Str != empty<\/code> &#8211; the order of expression is reversed resulting in a null pointer exception<\/li><\/ul>\n\n\n\n<p><strong>Compliant example:<\/strong><\/p>\n\n\n\n<p>Only two ways how to correctly check for empty string<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>if $Str != empty and trim($Str) != '' then $Str else 'empty'<\/code><\/li><li><code>if $Str = empty or trim($Str) = '' then 'empty' else $Str<\/code><\/li><\/ul>\n","protected":false},"featured_media":0,"parent":97,"menu_order":2,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-772","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/772"}],"collection":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=772"}],"version-history":[{"count":4,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/772\/revisions"}],"predecessor-version":[{"id":958,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/772\/revisions\/958"}],"up":[{"embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/97"}],"next":[{"title":"Conditions should always include at least one variable","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/reliability\/predictableconditionexpression","href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/1435"}],"prev":[{"title":"Chain of \"if\/else if\" statements should have different conditions","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/reliability\/identicalifelseifcondition","href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/698"}],"wp:attachment":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=772"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}