Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do people often omit public/private/protected when declaring a class?

Tags:

oop

php

class

I keep seeing this format in recent codes and even here:

class Class {
    function this() {}
}

instead of

class Class {
    [public/private/protected] function this() {}
}
  1. Isn't it recommended to always specify the function scope?
  2. Isn't the first approach an old one?
  3. How are, in the first approach, defined private and protected functions?
like image 702
Shoe Avatar asked May 03 '11 16:05

Shoe


1 Answers

when you declare a function without any keyword that is public by default.

Isn't it recommended to always specify the function scope?

You have to define function scope if you are going to use them as private or protected.

Isn't the first approach an old one?

What's the old and new if they are still accepted by PHP.

How are, in the first approach, defined private and protected functions?

you can not with first approach you have to use keywords.

like image 94
Shakti Singh Avatar answered Nov 15 '22 06:11

Shakti Singh