Laravel

PHP Basics

Variables & constants, types, arrays, control flow, functions, namespaces, error handling

25 pertanyaan wawancaraยท
Junior
1

What is the main difference between a variable and a constant in PHP?

Jawaban

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.

2

How to correctly declare a variable in PHP?

Jawaban

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.

3

What is the data type returned by the following expression: 5 + 3.2?

Jawaban

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.

4

Which function checks if a variable is defined and not null?

5

How to declare a class constant in PHP?

+22 pertanyaan wawancara

Kuasai Laravel untuk wawancara berikutnya

Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.

Mulai gratis