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

All Questions

Tagged with
23 votes
3 answers
22k views

Strange behavior when overriding private methods

Consider the following piece of code: class foo { private function m() { echo 'foo->m() '; } public function call() { $this->m(); } } class bar extends foo { ...
NullUserException's user avatar
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
4 votes
1 answer
5k views

Private method overriding and visibility

I'm having a hard time trying to understand the output of the following code: class Bar { public function test() { $this->testPublic(); $this->testPrivate(); } ...
renatov's user avatar
  • 5,065
33 votes
9 answers
55k views

Call private methods and private properties from outside a class in PHP

I want to access private methods and variables from outside the classes in very rare specific cases. I've seen that this is not be possible although introspection is used. The specific case is the ...
Pablo López Torres's user avatar
71 votes
3 answers
38k views

Is there any way to set a private/protected static property using reflection classes?

I am trying to perform a backup/restore function for static properties of classes. I can get a list of all of the static properties and their values using the reflection objects getStaticProperties() ...
dqhendricks's user avatar
  • 19.2k
25 votes
1 answer
24k views

Can traits have properties & methods with private & protected visibility? Can traits have constructor, destructor & class-constants?

I've never seen a single trait where properties and methods are private or protected. Every time I worked with traits I observed that all the properties and methods declared into any trait are ...
user avatar
10 votes
3 answers
12k views

PHP Inherited parent method can't access child's private property

First of all: A quite similar problem has been posted and somehow solved already, but is still not answering my specific problem. More about this later. In words: I have a base class which provides ...
Jan's user avatar
  • 103
3 votes
2 answers
3k views

is there anyway to define public or private or protected classes in PHP

Is there anyway to create public or private or protected classes in a namespace just like java? like... namespace foo; public class Account { ....... } private class PrivateAccount { ....... } ...
SuVeRa's user avatar
  • 2,854
2 votes
3 answers
2k views

PHP: how to access variables inside a function that have been declared outside of it?

At the very beginning of each page I include a file that starts the SESSION etc, lets call it session.php. In this file session.php, I include a file that contains a function, let's call it function1....
Chris's user avatar
  • 3,836
1 vote
1 answer
89 views

Trouble showing images in other pages than Home (wordpress/html/css)

Hi I have a small website im doing for a customer and I have used a html/css-site and transferred it to wordpress by using blank theme. So far so good, have a look at energyshop.se if u want and in ...
Emanuel Olsson's user avatar
11 votes
2 answers
4k views

PHP friend/package visibility

Is there any way to limit the visibility in PHP in the same way as "package" visibility works in Java or at least "friend" visibility in C++? What's the best practice to maintain large OOP project and ...
Pavel S.'s user avatar
  • 12.2k
7 votes
3 answers
3k views

Checking method visibility in PHP

Is there any way of checking if a class method has been declared as private or public? I'm working on a controller where the url is mapped to methods in the class, and I only want to trigger the ...
phobia's user avatar
  • 567
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
6 votes
1 answer
4k views

Laravel / Eloquent Model Attribute Visibility

Previously ORM's i've used have mapped database columns directly to class properties which allowed you to specific property visibility, just as you normally would to restrict access to certain ...
Andy Burton's user avatar
6 votes
3 answers
5k views

How to prevent usage of public parent methods in child instance in PHP?

So let's say I have classes called parent and child, which will be then used from PHP file called caller.php class Child extends Parent { } class Parent { public function parentMethod(){ }...
Firze's user avatar
  • 4,019

15 30 50 per page