Php

Asked • 06/05/19

What is the difference between public, private, and protected in PHP?

When and why should I use `public`, `private`, and `protected` functions and variables inside a class? What is the difference between them? Examples: // Public public $variable; public function doSomething() { // ... } // Private private $variable; private function doSomething() { // ... } // Protected protected $variable; protected function doSomething() { // ... }

1 Expert Answer

By:

Jacob C. answered • 09/30/19

Tutor
5 (5)

Senior PHP Developer with Laravel, CodeIgniter, Wordpress experience

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.