Skip to content
Advertisement

Tag: oop

PHP Methods and Class Design [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year. Improve this question Which design concept is better in PHP; passing variable to the function myFunct() or not passing the variable? Here is maybe a

Accessing a public/private function inside a static function?

Due to the fact that you can not use $this-> inside a static functio, how are you supposed to access regular functions inside a static? This throws an error, because you can’t use $this-> inside a static. This throws the following error: How can you access regular methods inside a static method? In the same class* Answer Static methods can

Using the “new” keyword in constructors

I’ve recently read that using the keyword “new” in a constructor is highly frowned upon, but I’m not sure I understand why? For example, how is: class A { public $foo; function __construct() …

PHP Interface: Specify ANY visibility

I’m making use of an interface for a set of classes. I have a problem however because I wish for any visibility to be allowed in the interface (That is: public, protected and private). I need the parent method to only be protected and I need the child method to be private, but I get the error saying Fatal error:

Creating an array of objects in PHP

I would like to know what is the right of creating objects arrays in php. My goal here is to be able to get data like this: Thanks for your time. EDIT: And if I want to do it in class it should look like this? Answer Any of the following are valid:

Extending ArrayObject in PHP properly?

Problem: I am trying to extend PHP’s ArrayObject as shown below. Unfortunately I can’t get it to work properly when setting multi-dimensional objects and instead an error thrown as I have the strict settings enabled in PHP. (Error: Strict standards: Creating default object from empty value) Question: How can I modify my class to automatically create non-existing levels for me?

Call method by string?

This doesn’t work: Is the only possibility to use call_user_func();? Answer Try: Be sure to check if the action is allowed and it is callable

PHP using an array in a Validation Class

On my site I have my register page, where a user inputs his information to register to my site. When he does the I process the user inputted information. Now when processing it I’m using arrays to facilitate the process, and not have me write the same code over and over. For example, here is how I gather the user

Advertisement