Site icon Netopsiyon Online

PHP Comment Lines and Their Importance

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?

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;

< ?php
/*
system_xxxx.php
Copyright (c) 2018 Netopsion
All rights reserved.
*/

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.

< ?php
/*
* system_xxx.php
*
* Copyright (c) 2018 Netopsiyon
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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.

< ?php
###########
# Project Name:
# Creation Date:
# Revision Date:
# Revision No:
# Preparer:
# Checked and Approved by:
# MD5SUM Information:
# File name:
# Purpose of Use:
#######################

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.

$sql = “SELECT * FROM licenses WHERE idcode='” . $_POST[ “id” ] . “‘ and date='” . $_POST[ “date” ] . “‘” ;

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 .

$sql = “SELECT * FROM licenses WHERE idcode='” . $_POST[ “id” ] . “‘ and date='” . $_POST[ “date” ] . “‘” ;
echo $sql ;

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;

$sql = “SELECT * FROM licenses WHERE idcode='” . $_POST[ “id” ] . “‘ and date='” . $_POST[ “date” ] . “‘” ;
//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;

$row = mysqli_fetch_array ( $sql ) ;
echo “<pre>” ;
print_r ( $row ) ;
echo “</pre>” ;

We saw the screen, our data is coming correctly. We are done. Let’s disable the codes by making them comments.

$row = mysqli_fetch_array ( $sql ) ;
/*
echo “<pre>”;
print_r($row);
echo “</pre>”;
*/

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.

Exit mobile version