All Questions
Tagged with visibility php
142
questions
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 ? $...
1
vote
1
answer
225
views
PHP Error: Cannot access private property
I have a class like this:
class Session {
private Session_Database $db;
public function __construct(){
// Instantiate new Database object
$this->db = new Session_Database();...
2
votes
3
answers
3k
views
Add custom column product visibility to admin product list in Woocommerce 3
I am trying to add a custom column to admin product list with the Catalog Visibility value of the products (basically, I need to know easier which is Hidden and which is not).
My code so far for my ...
1
vote
1
answer
41
views
Why is my class not visible outside the file? [closed]
I have 2 PHP files as part of a website. The first one has the API functions (pre made ready to use requests), and the other one has the code itself that will call the functions from the first one.
...
0
votes
1
answer
743
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 ...
0
votes
1
answer
2k
views
How to hide when ACF relationship field is empty on Elementor without using a plugin
I have a custom post type called "Product" and I have ACF relationship field called meta_product_hands_on_review to pull related review posts in the product.
I would like to hide a link &...
0
votes
1
answer
68
views
Change visibility of content by header
I need to redirect the user in this code example, so I don't have a option.
But I want to make a Box visible, when the result is success, but I can't echo the visibility by the ID, and I can't find a ...
0
votes
1
answer
118
views
PHP class loaded by child process becomes visible in parent process?
I am trying to add a mechanism for loading classes on demand and then basically unloaded them / being able to reload them. Essentially, each time the class is needed, it should be loaded freshly from ...
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() ...
0
votes
0
answers
346
views
How to change visibility of any method from a PHP object on runtime?
Ok folks, this is what I'm trying to accomplish here.
I want to call a method each time that another method is called, like a middle man.
I'm aware of these magic methods: __call($method, $args) and ...
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(){
}...
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 ...
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?
&...
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 ...
2
votes
2
answers
719
views
PHP: understanding $this - calling base class method instead of child method
Reading the PHP.net documentation I stumbled upon a problem that twisted the way I understand $this:
class C {
public function speak_child() {
//echo get_class($this);//D
echo $...