All Questions
19
questions
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
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
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....
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 = $...
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 ...
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?
&...
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 ...
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(){
}...
-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 $...
3
votes
2
answers
1k
views
Access Sibling Class Method
I'm working on a basic MVC for practice, but I get this error:
Fatal error: Call to a member function run() on a non-object in Router.php on line 5
What am I doing wrong?
Core:
<?php
class ...
0
votes
4
answers
89
views
object oriented programming inheritance
I have created this parent class
class DBMysqli {
private $mysqli;
function __construct($Mysqli) {
$this->mysqli = $Mysqli;
}
public function GET($queryArr){
$...
0
votes
1
answer
845
views
PHP - mysql_query() inside a static function of a class
The Situation
I have a table in a DB that contains job types, basically defined by a label and a price. I'm trying to do a simple SELECT * FROM jobtype but I can't seem to get it to work, although I'...
1
vote
2
answers
709
views
PHP Private property visible outside of object (within same class)
In this example, I have an abstract class and two regular classes. The abstract class is not supposed to be used alone, so its constructor is protected. Some functions are defined within the abstract ...
0
votes
2
answers
858
views
How can I protect a class property from extending classes in PHP?
Is it possible to do something like this:
class foo {
private $private = 'A';
}
class bar extends foo {
echo $this->private;
}
bar returns null...
I'd really like it if the variable $...
6
votes
5
answers
2k
views
Is visibility in PHP classes important, and why?
As you know, PHP class has private, public and protected keywords. I just started to write classes and I wonder what are the advantages of class visibility in PHP5.
And of course also disadvantages.....