PHP Advanced Techniques and Frameworks Flashcards
(25 cards)
What are namespaces in PHP?
Namespaces organize code to prevent naming conflicts, defined with namespace MyNamespace;.
Namespaces group classes or functions, like MyNamespace\MyClass. In WordPress, they’re used in plugins to avoid conflicts. Freelancers use namespaces for modular plugins, while enterprise architects ensure clean code organization in large systems, aligning with your OOP knowledge.
How do you use a namespace in PHP?
Use use to import a namespace, like use MyNamespace\MyClass; $obj = new MyClass();.
Importing simplifies class access. In WordPress, plugins use use for external libraries. Freelancers streamline code, while enterprise architects manage namespace imports for scalability.
What is autoloading in PHP?
Autoloading automatically includes class files when needed, using spl_autoload_register().
For example, spl_autoload_register(function($class) { include $class . ‘.php’; });. In WordPress, autoloaders load plugin classes. Freelancers simplify file management, while enterprise architects optimize autoloading for performance.
What is Composer in PHP?
Composer is a dependency manager for PHP, installing libraries via composer.json.
It manages packages like Guzzle for APIs. In WordPress, Composer is used for plugin dependencies. Freelancers streamline development, while enterprise architects ensure dependency versioning for enterprise systems.
How do you install a package with Composer?
Use composer require vendor/package, like composer require guzzlehttp/guzzle.
Adds the package to composer.json and downloads it. Freelancers use it for WordPress integrations, while enterprise architects enforce version control for stability, per your API deck.
What is the composer.json file?
composer.json defines project dependencies and metadata, like “require”: {“guzzlehttp/guzzle”: “^7.0”}.
In WordPress, it manages plugin libraries. Freelancers configure it for clients, while enterprise architects ensure compatibility across large projects.
What is the vendor directory in Composer?
The vendor directory stores Composer-installed packages and the autoloader.
Includes files like vendor/autoload.php. In WordPress, it’s used for external libraries. Freelancers include the autoloader, while enterprise architects secure the directory.
What is PSR-4 autoloading in PHP?
PSR-4 is a standard for mapping namespaces to file paths in autoloading.
For example, MyNamespace\Class maps to src/Class.php. In WordPress, plugins follow PSR-4. Freelancers standardize code, while enterprise architects enforce PSR-4 for maintainability.
What are traits in PHP?
Traits are reusable code blocks included with use, like trait MyTrait { public function myMethod() {} }.
In WordPress, traits share plugin logic. Given your OOP experience, freelancers use traits for modularity, while enterprise architects avoid conflicts in large codebases.
How do you use a trait in PHP?
Use use inside a class, like class MyClass { use MyTrait; }.
Adds trait methods to the class. In WordPress, plugins use traits for shared functionality. Freelancers simplify code, while enterprise architects ensure trait compatibility.
What is Laravel in PHP?
Laravel is a PHP framework for building robust web applications.
It offers features like Eloquent ORM and routing. Freelancers use Laravel for custom apps beyond WordPress, while enterprise architects leverage it for scalable enterprise systems.
What is Eloquent ORM in Laravel?
Eloquent ORM maps database tables to PHP classes for intuitive queries.
For example, User::where(‘name’, ‘John’)->get();. Freelancers use it for client apps, while enterprise architects design data models, complementing your database deck.
What is a Laravel route?
A route maps a URL to a controller or closure, like Route::get(‘/users’, [UserController::class, ‘index’]);.
Defines API endpoints or pages. Freelancers build routes for custom APIs, while enterprise architects create RESTful routes for enterprise services.
What is Symfony in PHP?
Symfony is a PHP framework for building modular, high-performance applications.
It’s used in parts of WordPress (e.g., HTTP Foundation). Freelancers use Symfony for complex projects, while enterprise architects leverage its components for enterprise solutions.
What is the Timber library in WordPress?
Timber is a WordPress library for using Twig templates with PHP.
It separates PHP logic from HTML, like Timber::render(‘template.twig’, $data);. Freelancers create clean themes, while enterprise architects use Timber for maintainable frontends.
What is Twig in PHP?
Twig is a templating engine for secure, readable PHP templates.
Used with Timber in WordPress, it renders views like {{ post.title }}. Freelancers enhance theme readability, while enterprise architects ensure secure template rendering.
What is dependency injection in PHP?
Dependency injection passes dependencies to a class, like public function __construct(Database $db) { $this->db = $db; }.
In WordPress, plugins inject services. Freelancers improve modularity, while enterprise architects design injectable systems for scalability, per your OOP deck.
What is a service container in PHP?
A service container manages class dependencies, like Laravel’s container.
It resolves dependencies automatically. Freelancers use containers in frameworks, while enterprise architects build custom containers for enterprise applications.
What is middleware in PHP frameworks?
Middleware processes HTTP requests before reaching the application, like auth middleware in Laravel.
In WordPress, plugins use hooks as pseudo-middleware. Freelancers secure routes, while enterprise architects implement middleware for request filtering.
What is a PHP closure in advanced contexts?
A closure is an anonymous function capturing external variables, like $fn = function() use ($x) { return $x; };.
In WordPress, closures are used in hooks. Freelancers leverage closures for callbacks, while enterprise architects use them in functional patterns, per your functions deck.
What is the callable type in PHP?
A callable is a type for functions or methods, like call_user_func($callable, $arg);.
In WordPress, it’s used for dynamic callbacks. Freelancers use callables in plugins, while enterprise architects ensure type safety in complex systems.
What is a generator in PHP?
A generator yields values one at a time, like function gen() { yield 1; yield 2; }.
Saves memory for large datasets. In WordPress, generators process post lists. Freelancers optimize performance, while enterprise architects handle big data efficiently.
What is PHPUnit in PHP?
PHPUnit is a testing framework for writing and running PHP unit tests.
Tests ensure code reliability. In WordPress, plugins are tested with PHPUnit. Freelancers write tests for clients, while enterprise architects enforce testing for quality assurance.
What is a design pattern in PHP?
A design pattern is a reusable solution to common problems, like the Singleton pattern.
In WordPress, plugins use patterns (e.g., Factory). Freelancers apply patterns for maintainability, while enterprise architects design systems with patterns like Dependency Injection.