Skip to content

Php Programming

Master Php Programming with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.

🎓 50 cards ⏱️ ~25 min Advanced
Study Full Deck →
Share: 𝕏 Twitter LinkedIn WhatsApp

🎯 What You'll Learn

Preview Questions

12 shown

What is a class in PHP OOP?

Show ▼

A class is a blueprint for creating objects. It defines properties (variables) and methods (functions) that the objects will have.
class User { public string $name; }

What is the difference between public, protected, and private visibility in PHP?

Show ▼

public – accessible from anywhere.
protected – accessible within the class and its subclasses.
private – accessible only within the defining class.
These are known as access modifiers.

How do you create an object from a class in PHP?

Show ▼

Use the new keyword:
$user = new User();
This calls the class constructor (__construct) if one is defined.

What is the purpose of the __construct() magic method?

Show ▼

__construct() is the constructor that runs automatically when an object is created with new.
public function __construct(public string $name) {}
It initializes object properties.

What is inheritance in PHP?

Show ▼

Inheritance lets a child class extend a parent class using the extends keyword.
class Admin extends User {}
The child inherits all public and protected properties and methods.

What is an interface in PHP?

Show ▼

An interface defines a contract of methods a class must implement, without providing the method bodies.
interface Loggable { public function log(): void; }
A class uses implements to adopt it.

Can a PHP class implement multiple interfaces?

Show ▼

Yes. A class can implement multiple interfaces separated by commas:
class Report implements Printable, Exportable { }
This provides a form of multiple inheritance for contracts.

What is a trait in PHP?

Show ▼

A trait is a mechanism for code reuse in single-inheritance languages. It groups methods that can be included in multiple classes.
trait Timestampable { public function now() { return time(); } }

How do you use a trait inside a class?

Show ▼

Use the use keyword inside the class body:
class Post { use Timestampable; }
The class then gains all methods defined in the trait.

What happens when two traits define a method with the same name?

Show ▼

A fatal error occurs unless you resolve the conflict using insteadof or as:
use TraitA, TraitB { TraitA::log insteadof TraitB; }

What are namespaces in PHP?

Show ▼

Namespaces organize code and prevent name collisions between classes, functions, and constants.
namespace App\Models;
They act like virtual directories for your code.

How do you import a namespaced class in PHP?

Show ▼

Use the use statement at the top of the file:
use App\Models\User;
You can also alias it: use App\Models\User as AppUser;

🎓 Start studying Php Programming

🎮 Study Modes Available

🔄

Flashcards

Flip to reveal

🧠

Focus Mode

Spaced repetition

Multiple Choice

Test your knowledge

⌨️

Type Answer

Active recall

📚

Learn Mode

Multi-round mastery

🎯

Match Game

Memory challenge

Related Topics in Programming

📖 Learning Resources