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

What is the difference between using self and $this ?

Câu trả lời

Here is an explanation of the difference between using self and $this in PHP:

self vs $this

In PHP, self and $this are both used to access class members, but they differ in how they are used and what they refer to:

self

  • self is a keyword used to access static members of a class (class properties and methods).
  • It is used without an object instance, as it refers to the current class itself.
  • self is resolved at compile-time, meaning it is determined based on where the code is written, not where it is called from.
  • Example: `self::$staticProperty...
middle

middle

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

junior

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

junior

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

senior

How to turn errors into exceptions in PHP?

Bình luận

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

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