Câu hỏi phỏng vấn PHP
Câu hỏi

In PHP, objects are they passed by value or by reference?

Câu trả lời

In PHP, objects are passed by reference by default. This means that when you pass an object as an argument to a function or assign it to a new variable, both the original variable and the new one refer to the same object in memory.

Here's an example to illustrate this:

class Person {
    public $name;

    public function __construct($name) {
        $this->name = $name;
    }
}

$person1 = new Person("John");
$person2 = $person1;

echo $person1->name; // Output: John
echo $person2->name; // Output: John

$person2->name = "Jane";

echo $person1->name; // Output: Jane
echo $person2->name; // Output: Jane

In this example, when we assign $person1 to $person2...

junior

junior

Gợi ý câu hỏi phỏng vấn

entry

What is the return type of a function that doesn't return anything?

junior

What is the differences between $a != $b and $a !== $b ?

junior

Is there a difference between isset and !empty ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào