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 reverse htmlentities() / What is the opposite of htmlentities()?

How does PHP compare objects?

How to namespace a Laravel route group?

What is the spaceship operator (<=>) in PHP?

How to install and use optipng on Linux CentOS

How to remove .php from the end of URLs with .htaccess

How to do comments in Blade files?

How to change the order that migrations happen?

What is YAGNI?

What are Template literals (Template strings) in JS?