Hello. Although these PHP comments may seem unnecessary at first, they are actually very important. You understand the importance of this when you open and look at the codes years later. You are talking about nice things, why is there a need for them, I can almost hear you say.
Why Use Comments in PHP?
- To highlight some areas while writing codes;
- To remember easily when we re-enter and look at the codes;
- To create order and improve codes;
- To make it easier for other people to understand the codes when you open them;
- To add copyright and license information to codes;
- And for people like me, to deactivate some codes after seeing their results;
You can use it. It’s completely up to you. Let’s learn and use it together.
In PHP , #, // and /**/ are used for multiple lines to add comments . Let me explain their usage in simple terms.
The line starting with # and // becomes a comment line. What you write after these expressions is not seen as a comment, it is perceived as PHP code directly, PHP wants to run them but PHP gives an error. Because; the effect of these signs ends when you go to the next line. /**/ is used in such cases.
In the /**/ characters, you can write as much text as you want between the asterisks. For example;
These lines are comments. They are of no importance. Of course, it became a little shapeless like this. Let’s give it some shape and add some license information etc. to make it look better.
It looks better now, doesn’t it? 🙂 This is entirely up to your imagination, but if TSE, Certification, etc. processes are involved, we make it more orderly. How? Look, I added it below.
If you don’t add them like this, you will struggle to get documents. I got this template from a friend who came for TSE 🙂 Of course, these are not enough, you have to prepare and submit many documents such as Alpha and Beta tests..etc. If you want to get information on this subject, you can talk to a company that does brand and patent work. This is not my area 🙂
These are things that will usually appear in the first lines of the file.
While describing it above, I said , “And to deactivate some codes for people like me after seeing their results”, let me explain that.
Let’s say we wrote a SQL query. Our line should be like this.
Let’s echo the SQL we wrote in the line below to see if it is correct and if the POST data is coming correctly .
We can query the code written to the screen with phpmyadmin or mysql workbench and see the status. Then, let’s add a comment line to the beginning of where we wrote echo $sql;
Now our SQL query will not be visible on the screen. When we are completely done with the file, we can find the lines we disabled and delete them. Because the sections after the comment lines will no longer work. Or let’s do the same with /* */. Our query is as follows;
We saw the screen, our data is coming correctly. We are done. Let’s disable the codes by making them comments.
LET’S NOT FORGET: What you write between the comment lines will not be visible when you call the page from the browser.
I guess that’s enough. If you have any questions, you can write them in the comments.
Post Comment