Kritim Yantra
Jul 14, 2025
Answer:
PHP stands for Hypertext Preprocessor. Itโs an open-source, server-side scripting language designed for web development. It runs on the server and generates dynamic HTML content.
Answer:
Answer:
As of mid-2025, PHP 8.3 is the latest stable version. PHP 8.4 is expected to release later this year.
echo and print in PHP?Answer:
echo can take multiple arguments and is slightly fasterprint can only take one argument and always returns 1 (so it can be used in expressions)echo "Hello", " World!";
print "Hello World!";
Answer:
$name = "John";
$age = 25;
Variables in PHP start with a $ sign, and types are inferred (loosely typed).
Answer:
Answer:
define("SITE_NAME", "MyBlog");
Constants are declared using define() or const and cannot be changed after definition.
Answer:
Type hinting lets you specify data types for function arguments, return values, and class properties.
function greet(string $name): string {
return "Hello, $name!";
}
Answer:
Union types allow a variable to accept more than one type.
function showId(int|string $id) {
echo $id;
}
Introduced in PHP 8.0+.
Answer:
A special method (__construct) that gets called automatically when a new object is created.
class User {
public function __construct() {
echo "User created!";
}
}
Answer:
Attributes (introduced in PHP 8) allow metadata to be added to classes, functions, or properties.
#[Example]
class Test {}
Answer:
Enums allow defining a fixed set of possible values.
enum Status {
case Active;
case Inactive;
}
Introduced in PHP 8.1+.
$age = 18;
if ($age >= 18) {
echo "Adult";
} else {
echo "Minor";
}
switch ($color) {
case 'red':
echo "Red!";
break;
case 'blue':
echo "Blue!";
break;
default:
echo "Unknown";
}
$colors = ["red", "blue", "green"];
echo $colors[1]; // blue
Answer:
$assoc = ["name" => "John", "age" => 25];
$conn = mysqli_connect("localhost", "root", "", "mydb");
isset() and empty()?isset() checks if a variable is set and not nullempty() checks if a variable is empty (0, "", null, false, etc.)Answer:
Sessions are used to store user data across multiple pages (e.g., login sessions).
session_start();
$_SESSION['user'] = "John";
GET and POST methods in forms?try {
// risky code
} catch (Exception $e) {
echo $e->getMessage();
}
Answer:
Traits let you reuse code across multiple classes.
trait Logger {
public function log($msg) {
echo $msg;
}
}
Answer:
Built-in variables accessible globally:
$_GET, $_POST, $_SESSION, $_COOKIE, $_FILES, $_SERVER, $_ENV, $_REQUESTAnswer:
$user?->profile?->avatar
Prevents null errors by safely chaining object properties (introduced in PHP 8.0).
Answer:
Composer is the dependency manager for PHP, used to install libraries and manage packages.
composer require vendor/package
Answer:
PHP Standard Recommendations (PSRs) are coding standards (e.g., PSR-4 for autoloading, PSR-12 for code style).
Answer:
$square = function($x) {
return $x * $x;
};
include 'header.php';
require 'config.php';
include: gives a warning if the file is missingrequire: causes a fatal error== and ===?==: Compares values only===: Compares values and types1 == "1" // true
1 === "1" // false
$name = htmlspecialchars($_POST['name']);
Sanitization and validation are critical to prevent XSS or SQL injection.
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google
Kritim Yantra
Kritim Yantra