Note that there are some explanatory texts on larger screens.

plurals
  1. POOpensource project's PHP syntax
    text
    copied!<p>When working with open source project (like wordpress, drupal, joomla) I always find in the PHP pages a syntax like (this is an example from drupal):</p> <pre><code>&lt;?php if ($linked_site_logo or $linked_site_name): ?&gt; &lt;?php if ($title): ?&gt; &lt;div class="logo-site-name"&gt;&lt;strong&gt; &lt;?php if ($linked_site_logo): ?&gt;&lt;span id="logo"&gt;&lt;?php print $linked_site_logo; ?&gt;&lt;/span&gt;&lt;?php endif; ?&gt; &lt;?php if ($linked_site_name): ?&gt;&lt;span id="site-name"&gt;&lt;?php print $linked_site_name; ?&gt;&lt;/span&gt;&lt;?php endif; ?&gt; &lt;/strong&gt;&lt;/div&gt; &lt;?php else: /* Use h1 when the content title is empty */ ?&gt; &lt;h1 class="logo-site-name"&gt; &lt;?php if ($linked_site_logo): ?&gt;&lt;span id="logo"&gt;&lt;?php print $linked_site_logo; ?&gt;&lt;/span&gt;&lt;?php endif; ?&gt; &lt;?php if ($linked_site_name): ?&gt;&lt;span id="site-name"&gt;&lt;?php print $linked_site_name; ?&gt;&lt;/span&gt;&lt;?php endif; ?&gt; &lt;/h1&gt; &lt;?php endif; ?&gt; &lt;?php endif; ?&gt; </code></pre> <p>while I do use a different syntax writing my scripts; if I did wrote the previous example it would look something like:</p> <pre><code>&lt;?php if($linked_site_logo or $linked_site_name){ if($title){ echo '&lt;div class="logo-site-name"&gt;&lt;strong&gt;'; if($linked_site_logo){ echo '&lt;span id="logo"&gt;' . $linked_site_logo . '&lt;/span&gt;'; } if($linked_site_name){ echo '&lt;span id="site-name"&gt;' . $linked_site_name . '&lt;/span&gt;'; } echo '&lt;/strong&gt;&lt;/div&gt;'; }else{ /* Use h1 when the content title is empty */ echo '&lt;h1 class="logo-site-name"&gt;'; if($linked_site_logo){ echo '&lt;span id="logo"&gt;' . $linked_site_logo . '&lt;/span&gt;'; } if($linked_site_name){ echo '&lt;span id="site-name"&gt;' . $linked_site_name . '&lt;/span&gt;'; } echo '&lt;/h1&gt;'; } } ?&gt; </code></pre> <p>Now, lets skip the 'appareance' of the 2 syntax methods, becose it is maybe a matter of taste and/or custom (obviously I prefer the second method), the question is:</p> <p>Does the first syntax (breakinf the 'if' statements, output the HTML instead of echo it, have a lot of PHP snippets even if they arent really needed) have some technical advantages over the second one? (for example the script run faster, is easier to debug, etc...) Or is just a open source programmers unwrited convention?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload