How to add comments in PHP

PHP: How to add comments in PHP

Comments are parts of the code that don't really do anything (some exceptions) apart from be read by humans.

There are a few ways to add comments in PHP.

1: // - single line comments

  1. <?php
  2.         echo 'hello';
  3.         // this is a comment
  4.         echo 'world';

2: # - single line comments

  1. <?php
  2.         echo 'hello';
  3.         # this is a comment
  4.        echo 'world';

3: /* ... */ - multi line comments

  1. <?php
  2.         echo 'hello';
  3.         /* this is a comment
  4.         echo 'world';
  5.  
  6.         */
  7.         echo 'the end';

The only times that comments have any effect on the code that is processed is when some scripts scan 'DocComment'. A DocComment is one that starts like this /** ... */.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to add comments in PHP

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the PHP language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to change the order that migrations happen?

How to find the intersection (same values) from two arrays?

How to view all installed PHP modules?

How to get table column names from a database table in Eloquent?

How to make Apache force download of files (in .htaccess)

How to return an item in Eloquent, or throw a ModelNotFoundException exception if it isn't found?

Is multiple inheritance supported in PHP?

How to set up an alias to map one directory to another destination

What is an example of an object literal?

How to reverse htmlentities() / What is the opposite of htmlentities()?