Zend Certified PHP Engineer (ZCPE) Practice Test

Question: 1 / 400

What are the visibility keywords in PHP?

public, private, and static

public, protected, and private

The visibility keywords in PHP are primarily used to dictate the accessibility of class properties and methods. The correct answer highlights the three main visibility keywords: public, protected, and private.

When a property or method is declared as public, it can be accessed from anywhere - both inside the class itself and from outside the class or its instances. This makes public members very flexible and accessible to any part of the code that can access the object.

Protected members can only be accessed within the class itself and by inheriting classes. This provides a layer of encapsulation, allowing subclasses to interact with the inherited properties and methods while keeping them hidden from the rest of the program.

Private members are the most restrictive, as they can only be accessed within the class that declares them. This ensures a high level of encapsulation, protecting the class's internal structure and behavior from external interference.

The other choices, while mentioning some valid keywords, do not accurately represent the full set of visibility keywords in PHP. For example, static refers to a property or method's belonging to the class itself rather than instances of the class, and final is used to prevent class inheritance or method overriding, which are not directly related to visibility. Thus, only the selection that includes public, protected, and

Get further explanation with Examzify DeepDiveBeta

protected, static, and private

public, private, and final

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy