
PHP Basics
Variables & constants, types, arrays, control flow, functions, namespaces, error handling
1What is the main difference between a variable and a constant in PHP?
What is the main difference between a variable and a constant in PHP?
Risposta
A constant is defined once and its value cannot be modified afterwards, unlike a variable whose value can change at any time during script execution. Constants are declared with define() or const and do not require the $ symbol before their name. They are particularly useful for storing configuration values that should never change, such as file paths, base URLs, or API keys.
2How to correctly declare a variable in PHP?
How to correctly declare a variable in PHP?
Risposta
In PHP, all variables must start with the $ symbol followed by the variable name. The name can contain letters, numbers, and underscores, but must start with a letter or underscore. PHP is case-sensitive for variable names, meaning $name and $Name are two different variables. It is not necessary to declare the type when creating a variable because PHP is a dynamically typed language.
3What is the data type returned by the following expression: 5 + 3.2?
What is the data type returned by the following expression: 5 + 3.2?
Risposta
When an arithmetic operation involves an integer and a floating-point number, PHP automatically converts the result to a float to preserve decimal precision. This automatic type conversion is called type juggling or type coercion. In this example, 5 is an integer and 3.2 is a float, so the result 8.2 will automatically be a float. This is important behavior to understand to avoid calculation errors in financial or scientific applications.
Which function checks if a variable is defined and not null?
How to declare a class constant in PHP?
+22 domande da colloquio
Altri argomenti di colloquio Laravel
PHP OOP Essentials
Composer & Autoloading
Laravel Fundamentals
Laravel Routing
Blade Templates
Request & Response
Eloquent ORM Basics
Eloquent Relationships
Migrations & Schema Builder
Validation & Forms
Authentication
Authorization & Policies
API Resources & Authentication
Middleware
Service Container & DI
Queues & Jobs
Events & Listeners
Notifications & Mail
File Storage
Testing & PHPUnit
Caching
Livewire & Inertia
Eloquent Advanced
Repository Pattern
Laravel Packages
Performance Optimization
Security Best Practices
Laravel Octane
Laravel Distributed Systems
Observability & Monitoring
Deployment & DevOps
Padroneggia Laravel per il tuo prossimo colloquio
Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.
Inizia gratis