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 add a name prefix to all routes in a group?

How to do comments in Blade files?

What is the difference between reference and primitive data types types in Javascript?

How to show a specific view file for certain error codes?

Push vs Pop vs Shift vs Unshift

How to create random numbers in JS?

Point all requests to one PHP file

How do Invokable Controllers work in Laravel?

How to show (or log) all SQL queries executed by Laravel

What are macros in Laravel?