Sunday, December 8, 2024
HomeWeb application programmingPHP programmingPHP Syntax: Three Ways to Create Comments

PHP Syntax: Three Ways to Create Comments

PHP allows three different methods of formatting comments. All of these sytax examples will seem familiar to programmers of other languages.

Few things in programming stimulate as much conflict as commenting. Many code gods can just read the code like most of us read the newspaper. For these coding savants, commenting is seen as a frivolous waste of time.

However, for code monkeys like myself who can barely keep track of what was going on 5 minutes ago, it makes a lot of sense to me that code be heavily commented. Trying to struggle through poorly commented code is a torture.

Whatever your feelings on commenting, you will need to know the three different methods used to create comments within PHP code.

Comment Block

Slash-asterisk pairs are used to surround a multi-line comment block.

/* This is an example of slash-asterisk pairs being used to create a comment block. This comment block can be as long as required. This method is frequently used to "comment out" large blocks of code in testing. */

example of block comments in php

Inline Comments

The double slash (//) and pound sign (#) are the two methods used to create inline comments. Everything following either of these will be ignored and will be considered a comment.

$var++; // anything to the right of the double slash will be ignored
$var=2; # right of the pound sign is considered a comment

examples of inline commenting in PHP

David Kirk
David Kirk
David Kirk is one of the original founders of tech-recipes and is currently serving as editor-in-chief. Not only has he been crafting tutorials for over ten years, but in his other life he also enjoys taking care of critically ill patients as an ICU physician.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!