1. Home
  2. Computer Science MCQs
  3. PHP
  4. If you omit the visibility keyword in your method…

Added 22 Jan 2024

If you omit the visibility keyword in your method declaration, by default the method will be declared as.

  1. public Correct answer
  2. private
  3. protected
  4. friendly

Correct answer

A. public

11 views

MCQSEXAM

Explanation

If no visibility keyword is given, a PHP method is public by default, meaning it can be called from anywhere the object is accessible.

This default exists for backward compatibility with PHP 4, which had no visibility control. Modern coding standards such as PSR-12 still require visibility to be written out explicitly on every method and property.

Want more practice? Try the full set of Computer Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs