PHP interview questions

Total available count: 33
Subject - PHP Frameworks
Subsubject - PHP

Explain about various visibility in PHP?

The visibility of a property, method or (Till PHP 7.1.0) constant can be defined by prefixing the declaration with the keywords public, protected or private. Class members declared public can be accessed anywhere. Members declared protected can be accessed only within the class itself and by inheriting classes. Members declared as private may only be accessed by the class that defines the member.

1. Property visibility: Class properties must be defined as public/private/protected. If declared using var, then property will be defined as public.

2. Method visibility: Class methods may be defined as public/private/protected. Methods declared without any explicit visibility keywords are defined as public.

3. Constant visibility: As of PHP 7.1.0, class constants may be defined as public/private/protected. Constants declared without any explicit visibility keyword are defined as public.

4. Visibility from other objects: Objects of the same type will have access to each private and protected members even though they are not in same instances. This is due to the implementation of specific details are already known when inside those objects.

Next 5 interview question(s)

How to define constants?
How to execute a PHP script using command line?
PHP supports 8 primitive types. What are they?
What are Autoloading classes?
What are Classes?