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 the CSRF (Cross-site request forgery) token in Laravel?

How to check if a relation was loaded on an Eloquent model already?

How to select all rows for a certain month (or day, year or time), using Eloquent

Push vs Pop vs Shift vs Unshift

How could you include a custom function for every single time PHP runs?

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

How to change the order that migrations happen?

How to block an IP range based on CIDR in Apache with .htaccess

How to add comments in PHP

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