Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
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. ...
Mohammad Ayaad's user avatar
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 ...
InterLinked's user avatar
  • 1,374
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....
user1032531's user avatar
  • 25.9k
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 = $...
Mir-Ismaili'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
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
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
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(){ }...
Firze's user avatar
  • 4,019
-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
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 ...
user2336756's user avatar
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){ $...
devmonster's user avatar
  • 1,739
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'...
Justin Huss's user avatar
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 ...
basic6's user avatar
  • 3,761
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 $...
James Thompson's user avatar
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.....
kuzey beytar's user avatar
  • 3,187

15 30 50 per page