How to Comment in PHP
Part 1 of 2:
Styles
- Use single-line comments for short comments. If you need to leave a short comment, you can use the single-line comment code. The comment will only last to the end of the line or the end of the code block. These comments only work within PHP tags, and will be read if placed in HTML.[1]
- Use multi-line comments for longer comments or code testing. Multi-line comments are useful for writing a long explanation, or for preventing a segment of code from being processed. See the "Usage" section below for some tips on using multi-line comments.[2]
Part 2 of 2:
Usage
- Use comments to leave notes about how code works. You shouldn't have to do this for every line of code, since good code should be fairly easy to parse by other programmers. It is useful if the code is performing irregular or not obvious functions.[3]
// Generate curl request $session = curl_init($request); // Tell curl to use HTTP POST curl_setopt ($session, CURLOPT_POST, true);
- Leave comments so that you remember what you were doing. Whenever you're working on your own projects, comments can help you remember where you left off. Leave comments on code that isn't working properly, or that you haven't finished yet.
// Need to revisit the output for this before moving on echo "Hello World!";
- Comment on code you intend to share. If you plan on collaborating with others, or intend to make your code open-source, comments can help others figure out how your code functions and the best places to make improvements.[4]
/* Is there a more effective way to accomplish this? */ Gender: value="female">Female value="male">Male
- Use comments to keep specific blocks of code from being run. This is useful if you're testing something and need to prevent certain code from being run. Anything contained within the comment tags will be ignored when the page is loaded.
- Be careful when commenting out large blocks of code. The comment function will end whenever the first ending tag is hit, so if there's already a multi-line comment inside the code you comment out, the comment will only last until the end of the original nested comment.
- Use comments to create pseudo-documentation. You can use some creative code formatting to create documentation for your code directly in the code. This can be useful for open-source projects.
4.5 ★ | 2 Vote
You should read it
- Comment tag in HTML
- Guide to watching and managing video comments on Youtube
- How to censor comments on your YouTube channel?
- Top best Facebook comment photos
- Facebook confirms it is testing comments with stickers
- Good comments in Korean so you can send to idols
- How to use comments, notes (comments) in Word
- How to censor, block comments, unblock comments on Facebook Fanpage
May be interested
- How to Comment on YouTubethis article shows you how to comment on videos on youtube, as well as how to comment in a way that gets more likes and responses. you can use this method for both desktop and mobile versions of youtube.
- How to insert pictures into an Excel comment boxthis article will guide you to insert images into an excel comment box in the simplest and easiest way when using excel software.
- How to Comment with Timeline on YouTubethis tipsmake article will show you how to leave a comment with a timestamp so that it links to a point in the video on youtube.
- How to create an automatic comment filter on YouTubein addition to manually censoring youtube comments, we can completely create youtube automatic comment filters, to remove objectionable comments in your youtube channel.
- How to Insert a Comment Box in Word, PowerPoint, and Excelcommenting is a great feature built into the microsoft office programs for collaboration purposes. you will be able to insert your comment on any part of the document. this can be easily done on any version of microsoft office products....
- Beware of These 5 YouTube Comment Scams!youtube has a huge user base, which unfortunately makes it a prime target for scammers.
- Comment tag in HTMLthe comment tag is used to insert comments and comments in the code.
- How to write bold, italic, dash, ... on Comment Youtube, G +with just a few small steps below, you can write bold, italic or dash on youtube, g + to make a difference in countless other comments.
- Facebook has allowed commenting with colorful backgroundsrecently, facebook has added new features that allow users to write comments, comments with background color, similar to when posting facebook status with background color.
- How to insert comments in Excelto further explain the information for a certain cell on sheet, users often use the comment function (comment). when using the comment function, users easily attach information to the cell which does not show content in this data box.