<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>what is true, and can be optimized, is that PHP is smart enoughto
      know that</p>
    <p>empty(array()) == true</p>
    <p>so you could avoid the count() in this particular case</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 5/5/21 17:24, Joe Bordes wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:49ac5cd1-2917-57ac-2e5c-fedbb5d11ffb@tsolucio.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <p>Sadly, PHP warning system doesn't work that way:</p>
      <p>----</p>
      <p><?php<br>
        error_reporting(-1);<br>
        ini_set('display_errors', 1);<br>
        <br>
        if ($nothere) {<br>
            echo "it is here";<br>
        } else {<br>
            echo "it isn't here";<br>
        }<br>
        -----</p>
      <p>result</p>
      <p>-----<br>
      </p>
      <p>joe@linuxmint:/var/www/coreBOSTest$ php k.php <br>
        PHP Notice:  Undefined variable: nothere in
        /var/www/coreBOSTest/k.php on line 5<br>
        PHP Stack trace:<br>
        PHP   1. {main}() /var/www/coreBOSTest/k.php:0<br>
        <br>
        Notice: Undefined variable: nothere in
        /var/www/coreBOSTest/k.php on line 5<br>
        <br>
        Call Stack:<br>
            0.0001     393600   1. {main}() /var/www/coreBOSTest/k.php:0<br>
        <br>
        it isn't here<br>
      </p>
      <p>------<br>
      </p>
      <p><br>
      </p>
      <p>so you get the warning if the variable is not defined which is
        what you are trying to avoid</p>
      <p><br>
      </p>
      <p><br>
      </p>
      <p><br>
      </p>
      <div class="moz-cite-prefix">On 5/5/21 17:04, Sukhdev Mohan wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:BB1184C6-8802-4244-A055-2AC007F81334@myti.it">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        <blockquote type="cite" class="">
          <blockquote type="cite" class="">if ($variableList) {<br
              class="">
          </blockquote>
          <br class="">
          would provide the same result? To me that simple if($var)
          statement says, "if $var is not equal to a boolean false, or
          0, or null then continue"...</blockquote>
        <div class=""><br class="">
        </div>
        Yup, $var = [] is still 0 so it’s a falsy value (love the C
        based programming languages).
        <div class=""><br class="">
        </div>
        <div class="">I’d like to propose, let’s anticipate the
          rejection instead of nested ifs for the expected values
          (normally ifs should be used to handle exceptions not for the
          basic functionalities), like this:</div>
        <div class=""><br class="">
        </div>
        <div class=""><font style="background-color: rgb(255, 255,
            236);" class="" face="Menlo">If(!$var) { // check what will
            break the code</font></div>
        <div class=""><font style="background-color: rgb(255, 255,
            236);" class="" face="Menlo">    // reject statement and
            exit routine</font></div>
        <div class=""><font style="background-color: rgb(255, 255,
            236);" class="" face="Menlo">}</font></div>
        <div class=""><font style="background-color: rgb(255, 255,
            236);" class="" face="Menlo"><br class="">
          </font></div>
        <div class=""><font style="background-color: rgb(255, 255,
            236);" class="" face="Menlo">// continue the normal flow</font></div>
        <div class=""><br class="">
        </div>
        <div class="">This would also improve readability as it’s short
          and you immediately see what can cause a break.</div>
        <div class=""><br class="">
          <div class="">
            <div dir="auto" style="caret-color: rgb(0, 0, 0); color:
              rgb(0, 0, 0); letter-spacing: normal; text-align: start;
              text-indent: 0px; text-transform: none; white-space:
              normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;
              text-decoration: none; word-wrap: break-word;
              -webkit-nbsp-mode: space; line-break: after-white-space;"
              class="">
              <div dir="auto" style="caret-color: rgb(0, 0, 0); color:
                rgb(0, 0, 0); letter-spacing: normal; text-align: start;
                text-indent: 0px; text-transform: none; white-space:
                normal; word-spacing: 0px; -webkit-text-stroke-width:
                0px; text-decoration: none; word-wrap: break-word;
                -webkit-nbsp-mode: space; line-break:
                after-white-space;" class="">
                <div dir="auto" style="caret-color: rgb(0, 0, 0); color:
                  rgb(0, 0, 0); letter-spacing: normal; text-align:
                  start; text-indent: 0px; text-transform: none;
                  white-space: normal; word-spacing: 0px;
                  -webkit-text-stroke-width: 0px; text-decoration: none;
                  word-wrap: break-word; -webkit-nbsp-mode: space;
                  line-break: after-white-space;" class="">
                  <div dir="auto" style="caret-color: rgb(0, 0, 0);
                    color: rgb(0, 0, 0); letter-spacing: normal;
                    text-align: start; text-indent: 0px; text-transform:
                    none; white-space: normal; word-spacing: 0px;
                    -webkit-text-stroke-width: 0px; text-decoration:
                    none; word-wrap: break-word; -webkit-nbsp-mode:
                    space; line-break: after-white-space;" class="">
                    <div dir="auto" style="caret-color: rgb(0, 0, 0);
                      color: rgb(0, 0, 0); letter-spacing: normal;
                      text-align: start; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; -webkit-text-stroke-width: 0px;
                      text-decoration: none; word-wrap: break-word;
                      -webkit-nbsp-mode: space; line-break:
                      after-white-space;" class="">
                      <div>Best Regards,<br class="">
                        <b class="">Sukhdev Mohan</b> | <b class="">Software Developer</b></div>
                    </div>
                    <br class="Apple-interchange-newline">
                  </div>
                  <br class="Apple-interchange-newline">
                </div>
                <br class="Apple-interchange-newline">
              </div>
              <br class="Apple-interchange-newline">
            </div>
            <br class="Apple-interchange-newline">
            <br class="Apple-interchange-newline">
          </div>
          <div><br class="">
            <blockquote type="cite" class="">
              <div class="">Il giorno 5 mag 2021, alle ore 16:14, Alan
                Lord <<a href="mailto:alanslists@gmail.com" class=""
                  moz-do-not-send="true">alanslists@gmail.com</a>> ha
                scritto:</div>
              <br class="Apple-interchange-newline">
              <div class="">
                <div class="">In the fairly recent past there have been
                  a number of minor commits made which, I guess, are to
                  help prevent php WARNING and/or NOTICE type messages,
                  e.g.<br class="">
                  <br class="">
                  Something like this:<br class="">
                  <br class="">
                  <blockquote type="cite" class="">if
                    (count($variableList) > 0) {<br class="">
                  </blockquote>
                  <br class="">
                  became this:<br class="">
                  <br class="">
                  <blockquote type="cite" class="">if
                    (!empty($variableList) &&
                    (count($variableList) > 0)) {<br class="">
                  </blockquote>
                  <br class="">
                  But this seem to be overkill...<br class="">
                  <br class="">
                  As I understand things simply doing this:<br class="">
                  <br class="">
                  <blockquote type="cite" class="">if ($variableList) {<br
                      class="">
                  </blockquote>
                  <br class="">
                  would provide the same result? To me that simple
                  if($var) statement says, "if $var is not equal to a
                  boolean false, or 0, or null then continue"...<br
                    class="">
                  <br class="">
                  count($var) would return an integer if $var is a
                  string, so it is not a useful explicit test for an
                  array.<br class="">
                  <br class="">
                  And from the php manual, empty($var) says "a variable
                  is considered empty if it does not exist or if its
                  value equals false"<br class="">
                  <br class="">
                  <br class="">
                  Thoughts / Comments?<br class="">
                  <br class="">
                  <br class="">
                  Al<br class="">
                  <br class="">
                  _______________________________________________<br
                    class="">
                  <a href="http://www.vtiger.com/" class=""
                    moz-do-not-send="true">http://www.vtiger.com/</a><br
                    class="">
                </div>
              </div>
            </blockquote>
          </div>
          <br class="">
        </div>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <pre class="moz-quote-pre" wrap="">_______________________________________________
<a class="moz-txt-link-freetext" href="http://www.vtiger.com/" moz-do-not-send="true">http://www.vtiger.com/</a></pre>
      </blockquote>
      <pre class="moz-signature" cols="72">-- 
Un saludo
Joe
TSolucio

JPL TSolució, S.L. garantiza la confidencialidad de los datos que obran en su poder y según lo estipulado por la LOPD 
(Ley Orgánica 15/1999 de 13 de diciembre de Protección de Datos de Carácter Personal). Este mensaje se dirige 
exclusivamente a su destinatario y puede contener información privilegiada o confidencial. Si no es vd. el destinatario 
indicado, queda notificado de que la lectura, utilización, divulgación y/o copia sin autorización está prohibida en 
virtud de la legislación vigente. Si ha recibido este mensaje por error, le rogamos que nos lo comunique inmediatamente 
por esta misma vía y proceda a su destrucción. El correo electrónico vía Internet no permite asegurar la confidencialidad 
de los mensajes que se transmiten ni su integridad o correcta recepción. JPL TSolució, S.L. no asume ninguna 
responsabilidad por estas circunstancias.</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
<a class="moz-txt-link-freetext" href="http://www.vtiger.com/">http://www.vtiger.com/</a></pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Un saludo
Joe
TSolucio

JPL TSolució, S.L. garantiza la confidencialidad de los datos que obran en su poder y según lo estipulado por la LOPD 
(Ley Orgánica 15/1999 de 13 de diciembre de Protección de Datos de Carácter Personal). Este mensaje se dirige 
exclusivamente a su destinatario y puede contener información privilegiada o confidencial. Si no es vd. el destinatario 
indicado, queda notificado de que la lectura, utilización, divulgación y/o copia sin autorización está prohibida en 
virtud de la legislación vigente. Si ha recibido este mensaje por error, le rogamos que nos lo comunique inmediatamente 
por esta misma vía y proceda a su destrucción. El correo electrónico vía Internet no permite asegurar la confidencialidad 
de los mensajes que se transmiten ni su integridad o correcta recepción. JPL TSolució, S.L. no asume ninguna 
responsabilidad por estas circunstancias.</pre>
  </body>
</html>