Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
135 votes
6 answers
38k views

Default visibility of class methods in PHP

I looked at the manual, but I can't seem to find the answer. What is the default visibility in PHP for methods without a visibility declaration? Does PHP have a package visibility like in Java? ...
Yada's user avatar
  • 30.9k
7 votes
2 answers
8k views

Method accessing protected property of another object of the same class

Should an object's method be able to access a protected property of another object of the same class? I'm coding in PHP, and I just discovered that an object's protected property is allowed to be ...
Jānis Elmeris's user avatar
0 votes
2 answers
150 views

Encapsulating and inheriting methods

I'm wondering if it's possible to encapsulate the methods of a class, but then expose them within a consuming class. For example (JFTR, I know this code is wrong) class Consumer{ public ...
sunwukung's user avatar
  • 2,815
3 votes
3 answers
563 views

PHP Scope and Class Instance Interaction

It seems as though different instances of a class can know about each others' private member variables. I have provided some code that attempts to showcase my issue, and I will try to explain it. We ...
Thomas Upton's user avatar
  • 1,881
1 vote
3 answers
2k views

Setters/Getters, Visibility [ OOP ] in PHP

I'm in the process of reformatting my class ( seen below ) - I think I made the mistake of setting everything with the same visibility in my class, whereas properties should really be private and ...
meder omuraliev's user avatar
1 vote
3 answers
1k views

PHP print_r and static member

I've got an instance of a DB object that's passed to a Session object, because the Session object has several methods that make use of DB object to execute SQL statements I had plan to store this DB ...
user avatar
23 votes
2 answers
6k views

__destruct visibility for PHP

Should the "visibility" for the __destruct() function be public or something else? I'm trying to write a standards doc for my group and this question came up.
Clutch's user avatar
  • 7,534

15 30 50 per page
1
6 7 8 9
10