PHP: Comments

PHP comment တွေဟာ HTML comment တွေနဲ့ ဆင်တူပါတယ်။ PHP comment တွေဟာလဲ special character တွေနဲ့ စပီး special character တွေနဲ့ပဲ ပြန်ပိတ်ပါတယ်။ အဲဒီကြားထဲမှာ ရေးထားတဲ့ စာသားအားလုံးကို Browser က ကျော်သွားပါတယ်။

HTML comment တွေကတော့ ကိုယ်ကိုတိုင်အတွက်၊ တခြား Web Developer တွေအတွက်၊ ကိုယ့်ရဲ့ Source Code ကို ဝင်ကြည့်တဲ့ Visitor တွေအတွက် Note လိုပါပဲ။ PHP comment တွေကတော့ php file ကို Browser ကနေ View Source လုပ်ပီးကြည့်လဲ မြင်ရပါဖူး။ PHP source file ကို ဖွင့်ကြည့်မှပဲ မြင်ရမှာပါ။ HTML comment ရဲ့ syntax ကို မေ့နေရင် အောက်မှာ ပြန်ကြည့်ပါ။

<!-- This is an HTML Comment -->

PHP Comment Syntax: Single Line Comment

HTML မှာ comment type တစ်မျိုးပဲရှိပေမယ့် PHP မှာတော့ နှစ်မျိုးရှိပါတယ်။ ပထမ တစ်မျိုးကတော့ Single Line comment ပါ။ Single Line comment အတွက် “//” ကို သုံးပါတယ်။ Code line တစ်လိုင်းထဲမှာ “//” ရဲ့ ညာဖက်က စာသားအားလုံးကို Interpreter က ကျော်သွားပါမယ်။

Example:

<?php
 echo "Hello World!"; // This will print out Hello World!
 echo "<br />How? Can you see my comment?"; // echo "nothing";
 // echo "My name's Goo Goo!";
 ?>

Output:

Hello World!
 How? Can you see my comment?

echo line တွေကို comment လုပ်လိုက်တဲ့ အတွက် execute မလုပ်တော့ပါဖူး။ ဒီ Single Line comment ကို နားလည်ရခက်တဲ့ line တွေမှာ quick note သဘောမျိုးသုံးနိုင်ပါတယ်။ နောက်ပြီး code line တစ်လိုင်းကို တစ်ခါထဲ ဖျက်မပစ်ဘဲ ယာယီသဘော ခဏ ဖယ်ထားချင်တဲ့ အခါမျိုးမှာလဲ အသုံးတဲ့ပါတယ်။

PHP Comment Syntax: Multiple Line Comment

Multiple Line comment တွေကိုတော့ code line တွေ အများကြီးကို ခဏဖယ်ထားရာမှာ (သို့) line အများကြီး Note ရေးချင်တဲ့ အခါမှာသုံးပါတယ်။ Multiple Line comment ကို “/*” နဲ့ စပြီး “*/” နဲ့ ပြန်ပိတ်ပေးရပါမယ်။

Example:

<?php
 /* This Echo statement will print out my greeting message to the
 place in which I reside on. In other words, the World. */
 echo "Hello World!";
 /* echo "My name is Doo Doo!";
 echo "No way! My name's Goo Goo, the stupid PHP Programmer!";
 */
 ?>

Output:

Hello World!

Good Commenting Practices

PHP programmer တွေမှ မဟုတ်ပါဘူး။ Programmer တိုင်းကို comment တွေကို သုံးဖြစ်အောင် သုံးပါလို့ ကျနော့်အနေနဲ့ အကြံပေးချင်ပါတယ်။ Programmer တော်တော်များများဟာ ရှုပ်ထွေးတဲ့ code တွေ ရေးရမှာ မပျင်းပေမယ့်၊ comment ကောင်းကောင်း ရေးဖို့ကိုတော့ အပျင်းထူတတ်ကြပါတယ်။ Comment ရေးတာ အပိုအလုပ်လို့လဲ ထင်တတ်ကြပါတယ်။

ဒါပေမယ့် ကိုယ်ကိုတိုင် ရေးထားတဲ့ comment မပါတဲ့ code တွေကိုပဲ တစ်နှစ်လောက် ကြာတဲ့ အခါမှာပြန်ကြည့်လိုက်ပါ။ ကိုယ်ဘာအဓိပ္ပါယ်နဲ့ ရေးထားတယ်ဆိုတာကို ကိုယ်ကိုတိုင် မမှတ်မိတော့တာမျိုးတွေ ဖြစ်တတ်ပါတယ်။ အခုနောက်ပိုင်းမှာ တခြား Programmer တွေနဲ့ တွဲရေးရတာတွေပဲ များလာပါတယ်။ အဲတော့ ကိုယ့် code ကို သူများ အလွယ်တကူ နားလည်နိုင်ဖို့ comment ကောင်းကောင်း ရေးတာ အကျင့်လုပ်ထားဖို့ လိုအပ်ပါတယ်။ Single Line comment တွေကို နည်းနည်း နားလည်ရခက်တဲ့ line တွေမှာ ထည့်ရေးပါ။ အဲထက်ပိုပီး အသေးစိတ်ရမယ်ဆိုရင်တော့ Multiple Line comment သုံးပီး Note အနေနဲ့ ရေးပေးပါ။ အနာဂတ်မှာ Programmer ကောင်း တစ်ယောက် ဖြစ်လာပါလိမ့်မယ်။

Facebook comments:

Leave a comment


*