Laravel & PHP Flashcards
What are variables in PHP?
Variables store data, and PHP supports various data types, including integers, floats, strings, arrays, and objects.
What are control structures in PHP?
Control structures include conditional statements (if, else, switch) for decision-making and loops (for, while, foreach) for iterating through data.
What are functions in PHP?
Functions are blocks of code that perform a specific task, defined using the function keyword. They can accept parameters and return values.
What are superglobals in PHP?
Superglobals are built-in variables like $_GET, $_POST, $_SESSION, $_COOKIE, etc., used to access global data.
What is file handling in PHP?
File handling involves functions for reading from and writing to files, such as fopen(), fread(), fwrite(), and fclose().
How is error handling done in PHP?
Error handling is done using try, catch, and throw for managing exceptions and handling errors.
What is MVC architecture in Laravel?
Laravel follows the Model-View-Controller pattern, separating the application logic (Model), user interface (View), and user input (Controller).
How does routing work in Laravel?
Laravel uses a simple routing system to define URL routes in the web.php file, linking URLs to specific controller actions.
What is Eloquent ORM in Laravel?
Eloquent ORM is an Object-Relational Mapping system that simplifies database interactions, allowing you to work with databases using PHP syntax instead of SQL.
What is Blade templating in Laravel?
Blade is Laravel’s templating engine that enables dynamic content rendering with an easy-to-use syntax.
What is middleware in Laravel?
Middleware consists of functions that run before or after requests, used for tasks like authentication and logging.
What is Artisan CLI in Laravel?
Artisan CLI is a command-line interface for running tasks like migrations, creating controllers, and more.
What are classes and objects in OOP?
A class is a blueprint for creating objects (instances). An object is an instance of a class that can contain properties and methods.
What is encapsulation in OOP?
Encapsulation is bundling data (properties) and methods that operate on the data within a class, restricting access to some components.
What is inheritance in OOP?
Inheritance is a mechanism where a new class (subclass) inherits properties and methods from an existing class (superclass), promoting code reusability.
What is polymorphism in OOP?
Polymorphism is the ability to use a single interface to represent different data types. For example, method overriding allows subclasses to provide a specific implementation of a method defined in the superclass.
What is abstraction in OOP?
Abstraction is hiding complex implementation details and showing only the essential features of an object. This can be achieved using abstract classes and interfaces.
What is the difference between == and === in PHP?
== checks for value equality, while === checks for value and type equality.
What is the purpose of Composer in Laravel?
Composer is a dependency manager for PHP that helps manage libraries and packages in Laravel.
How do you handle database migrations in Laravel?
Database migrations in Laravel are handled using Artisan commands to create and manage schema changes.
Can you explain the concept of a trait in PHP?
A trait is a mechanism for code reuse in single inheritance languages, allowing you to include methods in multiple classes.
What are access modifiers in OOP?
Access modifiers define the visibility of class properties and methods, commonly including public, private, and protected.
How does PHP’s garbage collector work?
PHP uses a reference counting mechanism to manage memory. If an object’s reference count is 0, it is eligible for garbage collection. PHP has a cycle collector that detects circular references to free memory.
What are the different types of PHP errors?
- Notice - minor errors (undefined variables)
- Warning - non-fatal errors (including a non-existent file)
- Fatal - critical errors that stop execution (calling a function that doesn’t exist)
- Parse - syntax errors
Explain the purpose of spl_autoload_register().
It allows dynamic class loading, removing the need for multiple require or include statements.
What are traits in PHP, and how do they differ from abstract classes?
Traits allow code reuse across multiple classes, without inheritance. Unlike abstract classes, traits cannot have constructors and don’t force implementation.