Skip to main content

All Questions

Tagged with
0 votes
1 answer
742 views

why can't I access a protected method from a private method if the protected ones are inherited by the subclasses?

I do not understand this particular case or what Alexander says. class instance is not the same as class? As already Alexander Larikov said that you can't access protected methods from class instance ...
user avatar
1 vote
2 answers
2k views

Private property in parent class can be accessed and re-assigned through the instance of child class in PHP but protected one can't

I am very confused why $produk1->harga = 500; can still make a change (or re-assign the value 500) to private $harga property despite private $harga in class Produk has PRIVATE visibility ? $...
didaen's user avatar
  • 48
4 votes
1 answer
814 views

Why can child override and access its parent private method?

I'm used to put method as protected in my PHP classes. But playing with private I'm starting to have doubts. I know that it might be a duplicate but I can't find clarity from the SO-answers I've ...
Kamafeather's user avatar
  • 9,471
0 votes
1 answer
535 views

Parent's protected properties inaccessible to child object

I have a parent class I'll be calling 'ParentClass' and a child class (that extends from it) which I'll be calling 'ChildClass'. ParentClass has protected properties $prop1 and $prop2 which I want ...
Douglas Silva's user avatar
2 votes
3 answers
2k views

PHP: Changing default visibility of undeclared class properties to protected/private

In PHP, undeclared class properties/variables will default to "public" visibility. Is there a way (for certain classes, but not all) to change the default visibility to "protected" (or private)? I ...
LaVache's user avatar
  • 2,579
0 votes
1 answer
130 views

Is it possible to truly limit access of this private property?

I'm using three tricks in my attempt: Reflections can't be used with dynamic class properties __get() or __set() must be called when accessing dynamic class properties debug_backtrace() can be ...
SOFe's user avatar
  • 8,081
-1 votes
1 answer
67 views

Strange PHP Reaction

I'm getting some wierd reactions when running this script. <?php error_reporting(E_ALL); class A { protected $varOne = array( "subVar1" => "", "subVar2"...
Alex's user avatar
  • 3
6 votes
2 answers
2k views

What's the visibility of a class by default in PHP?

I could find the default visibility of a property and a method in the PHP manual. But i couldn't find any info regarding the class itself. My guess is that it's public. But if someone could link to ...
Jo Smo's user avatar
  • 7,053
4 votes
3 answers
2k views

What is the difference between the keyword 'Private' and 'Final'?

Having a confusion between Private and Final in PHP. For example I have 3 classes: Class A (parent class) Class B (child class) Class C (other class) What I understand: A: Public variables and ...
M Gaidhane's user avatar
2 votes
2 answers
560 views

How do you override self?

I want to build class that implement a lot of methods based on it's id, so I want to have one class parent that implement the methods! and when i want to use this class I will extend it and just ...
david's user avatar
  • 3,340
4 votes
4 answers
2k views

How can protected property of a class be visible from a static method in PHP?

I understand OOP. What I understand so far is that private and protected cannot be referenced from outside the class using $this->blah notation. If that is correct, how can the following code work? &...
Chris Roy's user avatar
  • 953
0 votes
1 answer
38 views

PHP providing parameter visible only inslide class

I might not grasp nature of PHP OOP system so that's maybe not impossible but let me ask is there a way to create parameter that's accesible only by methods of this class? I want to craete 'local' ...
Szymon Toda's user avatar
  • 4,496
1 vote
1 answer
925 views

can classes have visibility to its namespace only

Is it possible to declare a class to be only visible or usable by other classes inside the same namespace? example: namespace Dirtyredz; class BikeStore{} private Class Bike{} I want Bike to only ...
DirtyRedz's user avatar
  • 566
-2 votes
1 answer
557 views

Cause of the error: “Using $this when not in object context protected function”

I get the following error when using the following class in my code: Using $this when not in object context protected function Here is my code: <?php class Sign { private $db; private $...
Billy Assim's user avatar
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

15 30 50 per page