All Questions
Tagged with visibility php
142
questions
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 ...