All Questions
Tagged with visibility php
142
questions
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();...
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 ...
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 ...
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 ? $...
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 $...
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 ...
-1
votes
1
answer
154
views
How handle visibility change of property in class when using serialized objects?
UPDATE:
As someone says this question is a bit unclear. I couldn't really understand it myself. But I did dig up the solution. It's a PHP bug that has been resolved. The server this legacy code runs ...
0
votes
1
answer
536
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 ...
0
votes
0
answers
38
views
How to make available only those public methods which are declared in interface?
In Java, for example, this comes out of the box due to static nature of the language. But in PHP this could be also useful especially to keep a code secure and clean from an architectural point of ...
1
vote
1
answer
26
views
PHP7 pthreads3 woes : Unable to increment public property of Threaded class from within an instantiated Worker object
I am confused by the results from the following simplified code.
A Threaded object MyPool is to instantiate a variable number of MyWorker objects. As each MyWorker object is correctly instantiated, ...
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 ...
6
votes
3
answers
2k
views
Why doesn't PHP's null coalescing operator (??) work on class constants with different visibilities?
Consider the example below. Class a has private const SOMETHING, but class b has protected const SOMETHING.
class a {
private const SOMETHING = 'This is a!';
public static function ...
0
votes
1
answer
265
views
Restrict getter and setter accessible properties
How should one use PHP's magic __get() and __set() methods and limit which properties are supported?
I've typically seen PHP's magic methods used for overloading the below two ways, and neither do so....
1
vote
1
answer
90
views
Elemente will make it invisible when clicked script in php
German will not appear when clicked and will show english. If English is clicked, German will appear. I've investigated hide, show, visibile parts. I even wrote a JavaScript script, but it did not ...
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 ...
2
votes
0
answers
42
views
How to access the method from trait after changing its visibility in the exhibiting class? [duplicate]
Consider below code :
<?php
trait HelloWorld {
public function sayHello() {
echo 'Hello World!';
}
}
// Change visibility of sayHello
class MyClass1 {
use HelloWorld { ...
0
votes
1
answer
279
views
Visibility of Dynamically Declared Field in PHP
What's the visibility (public, private, ...) of a field that dynamically has been declared (in PHP)?
class Foo {
public function __construct() {
$this->dynamicallyDeclaredField = $...
-1
votes
1
answer
459
views
Disable Woocommerce products based on their regular price value
On my Woocommerce website, I have a plugin which sometimes change product price to regular price = null (for different reasons).
When that happens, we'd like to disable the product so it doesn't ...
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 ...
3
votes
1
answer
134
views
PHP: set_error_handler and visibily
In my class constructor, I have the following:
set_error_handler(array(
$this,
'_custom_error_handler'
));
In the same class, I have the following method defined:
protected function ...
1
vote
4
answers
89
views
PHP to JQuery code conversion [If else]
How can I do it on JQuery? When I click hide, the element will be hidden, same goes for show, the element will be shown. How am I going to do it? Thanks!
<form method="POST">
<button type="...
-1
votes
2
answers
180
views
pdo variable is undefined in mysql function
I have an index.php which is like:
require_once("../resources/config.php");
require_once(LIBRARY_PATH . "/mysql.php");
...
if(checkIfMailExists($email)) {
$error = true;
$errormsg = "This e-...
3
votes
1
answer
3k
views
child class accessing parent's private method?
A user posted a comment on PHP Visibility manual page. It's the second most voted comment. He used this code example:
<?php
abstract class base {
public function inherited() {
$this-&...
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 ...
-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"...
2
votes
4
answers
535
views
PHP - Is public visibility less secure?
I once questioned a teacher why she used to set properties visibilities as private or protected ALWAYS. She answered me that this is more secure than setting it public, but I'm not really confident in ...