Comments in PHP

Making comments within the PHP code is a very simple but effective custom, which is to write within each block of code clarifications that are not useful when, several days, weeks or months later, we read the code to make some changes.

Comments in PHP | Learn PHP | Making comments within the PHP code is a very simple but effective custom, which is to write within each block of code clarifications that are not useful when, several days, weeks or months later, we read the code to make some changes

Making comments within the PHP code is a very simple but effective custom, which is to write within each block of code clarifications that are not useful when, several days, weeks or months later, we read the code to make some changes.

Remember that these comments do not reach the source code of the browser, so users of our sites cannot see them, as they are for our personal use and that of other programmers who have access to our code.

The aim of wrapping something in between comments is to make the PHP interpreter software not try to execute the words we write, but ignore them, and continue after the comment is finished.

Comments in PHP, just like in any other language, are very important, as they help other people to understand what we do with our lines of code, as well as help us when we program a web page, and after a time, we want to make modifications.

The comments will help us understand any part of the code in a simple way.

The comments we use can be of any kind. Each programmer follows some guidelines when making their codes, and there are those who do not use the comments.

For people who know other programming environments, such as C or C ++, it will not be difficult for them to learn to comment in PHP, since it is done exactly the same as in those programming languages.

First of all, we can use //, but it will only be useful to make comments in a single line; If we want to use several lines to make our comments, we will use to start the comment:

/* and to finish */

PHP allows you to write comments from one or several lines:

<?php
$variable=”value”; //comment of a line
$cifra = 123; #other comment of a line
echo $variable; /*Commentary
Multi
Line
*/
?>

A practical use is to clarify things that are useful to remember later, when reviewing this code:

<?php
$key=“xyz345”; //remember to notify the manager if we change it
$tolerancia =3; #is the number of incoming retries tolerated with the wrong password
echo $key; /*remember that if we show this,
previously we should inform the user,
so that he does not expose it to the sight of others
*/
?>

EXAMPLE

<?
phpinfo(); //with this example we see the configuration of the interpreter
// of PHP, we can check which parameters we have activated or
// deactivated and, if you have some knowledge, we can
// modify any of these parameters just like we have done
// previously in the configuration files.
// As we can see, this way of including comments in this
// example is not the most correct, since we use several lines and it is
// less effective when having to write it occupying a greater space
?>

The most correct thing to do the previous example would be to do it in this other way, since we avoid having to put // every time we modify this comment, and using / * * / we can modify the text of the comment without having to be aware of add the beginning of the comment again with //.

<?
phpinfo();
/ * With this example we see the configuration of the PHP interpreter, we can check which parameters are activated or deactivated and, if we have some knowledge, we can modify some of these parameters as we have done previously in the configuration files.
As we can see, this way of including comments in this example is more correct, since using several lines is more efficient than the previous example * /
?>

Another very practical use of the comments is to "deactivate" lines of code that we want not to be executed, but that we do not intend to delete them, but we only want to execute the file without the commented lines of code being executed. We discuss parts of the code, and it's as if they did not exist. This helps us in the detection of errors, if we comment on a line near the area where an error is occurring, to avoid its execution and help us detect what it is producing.

Did you like it or was it useful?

Help us share it in Social Networks

Professor at the University of Guadalajara

Hugo Delgado Desarrollador y Diseñador Web en Puerto Vallarta

Professional in Web Development and SEO Positioning for more than 10 continuous years.
We have more than 200 certificates and recognitions in the Academic and Professional trajectory, including diploma certificates certified by Google.

IT ALSO DESERVES TO PAY TO VISIT:

Not finding what you need?

Use our internal search to discover more information
Sponsored content:
 

Leave your Comment

SPONSOR

Your business can also appear here. More information