PHP CHAPTER 04

PHP Comments

Comments are notes inside source code that PHP does not execute.

📘

What is it?

Comments are notes inside source code that PHP does not execute.

💡

Why do we use it?

Comments explain code and make programs easier to understand and maintain.

⚙️

How does it work?

The PHP parser ignores text written as comments.

🧩

Syntax

PHP Syntax
// Single line
# Single line
/* Multi-line */
💻

Example

PHP Example
<?php

// Student name
$name = "Aman";

/* Display student name */
echo $name;

?>
🔍

Example Explained

// creates a single-line comment. /* */ creates a multi-line comment. Neither comment is executed.
🚀

More Examples

<?php # This is also a comment echo "Hello PHP"; ?>

⚠️ Important Rules

Use comments to explain why code exists, not to describe every obvious line.

❌ Common Mistakes

Accidentally commenting out code that is required for the program.

🌍 Real-World Use

Comments are useful in team development and maintenance.

📝 Practice Exercise

Create a student marks program and add meaningful comments to every major section.

💻 Try It Yourself

Write and run this PHP lesson inside the AIFA Coding Lab.

Open Coding Lab →