PHP programming question?

Does the following code below mean the same thing, and if so, when is it better to code? And is there a name when there are no curly braces in the PHP code?

PHP code.

<?php if (isset($_POST['email'])) { echo $_POST['email']; }?>
<?php if (isset($_POST['email'])) echo $_POST['email'];?>
+3
source share
5 answers

Personally, I always write statements that I can use curly braces with curly braces . For example, take the code:

if (UserIsLoggedIn())
    ShowCreditCardDetails();

Now, if some amateur coder comes in and wants to do something else when the user is logged in:

if (UserIsLoggedIn())
    WriteAuditLog();
    ShowCreditCardDetails();

It ShowCreditCardDetails()will now be launched for users who are not logged in, because only the first statement after ifis executed when there are no curly braces. If it were:

if (UserIsLoggedIn())
{
    ShowCreditCardDetails();
}

, .

, , if. . - .

+6

. , , , , :

if (isset($_POST['email'])) 
    echo $_POST['email'];

, , , script :

if (isset($_POST['email'])) 
    echo $_POST['email'];
    echo $_POST['foo'];

echo $_POST['foo']; , if. :

 <?php if (isset($_POST['email'])) echo $_POST['email'];  echo $_POST['foo'];?>

echo $_POST['foo']; if.


, , , . "" .

. .

+2

, , ;, if ( , , ). .

+1

. .

, . . .

<?php
if (isset($_POST['email']))
 {
 echo $_POST['email']; 
 }
?> 

.

0

There is no such thing as "best coding." This is a matter of agreement. Choose your favorite coding standardand follow his recommendations.

http://pear.php.net/manual/en/standards.php
http://framework.zend.com/manual/en/coding-standard.html

are examples and you can google for php coding standardfor more

-2
source

Source: https://habr.com/ru/post/1737654/


All Articles