PHP Programming Comment Types

Like any other programming language, PHP has its own comment syntax.

There are many PHP comment types which we will detail. Comments are part of the trivial elements in the success of a program, and that is why it is important to use them wisely.


  • What are programming comments?
  • Types of comments in PHP
    • Linear comment in PHP
    • Multi-line comments
    • Multiple Line Comment Example
    • Comment out PHP functions
  • Summary to comment in PHP

What are programming comments?

A comment, in a programming languageis a line written in a natural language (the developer’s native language, for example) that will not be executed by the interpreter (or the compiler, depending on the language used).

Its function is describe or explain a part of the code that would be difficult to decipher in case of maintenance or collaborative work (several developers working on the same program).

Therefore, feedback is particularly useful for a lone developer, but it is most useful when it comes to an entire team working on the same project.

Among other things, they allow you to enforce naming and organization when writing code for a collaborative project.

In addition, the comments ensure easier maintenance of the program by its author or a third party.

Another strength of the comments is the generation of technical documentation. In fact, there are apps like PHPDocumentor that rely on a particular comment syntax to generate application documentation quickly. This ensures a time saving significant for a development team.

Commenting a code is also part of the good practices to adopt in programming. However, one should not go into the opposite excess where each statement in the code would be commented out. Then clarity and readability of the program would be achieved.

Types of comments in PHP

There are two types of comments: the single line comment and the multi line comment.

Let’s study together the two methods to comment a text in a single line.

Linear comment in PHP

Here’s an example of a one-line comment, which is easy to do:

  // Este es el primer comentario lineal
  echo 'Hello World !';
  # Este es otro comentario lineal
  echo 'Buenos días mundo, desde!!';

PHP offers two ways to comment out text placed on a line. The most used method is the first with double slash (//) and it is a classic of programming.

The second option is by using the hash (#) metacharacter. The latter is less used in PHP.

Multi-line comments

Allows commenting on a text written on several lines. It is widely used by developers. These comments are defined by the symbols /* and */. The following example illustrates its use.

Multiple Line Comment Example

    Este es un comentario escrito en sublime text
   El siguiente código muestra el mensaje hola mundo.
  echo 'Hello World !';

Comment out PHP functions

One of the most common and “professional” uses of comments is usually explain the functionality of a function PHP.

The following code serves as a guide to explain functions both in PHP and in other programming languages ​​and is part of good practices:

  * Explicación de la función
  * @param NombreParametro y explicación
  * Pre: a tener en cuenta
function hola(){
   return true;

Summary to comment in PHP

  • You can make comments of one line or several.
  • Both natural language and PHP code can be commented.
  • Comments are often used to explain code.
  • Remember that there are comment placement standards for documentation.
  • Can

Leave a Reply