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
Tag: oop
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() …
How to programmatically find public properties of a class from inside one of it’s methods
I’ve got a class Foo with public and protected properties. Foo needs to have a non-static method, getPublicVars() that returns a list of all the public properties of Foo (this is just an example, I know from outside the Foo object calling get_object_vars() will accomplish this and there is no need for my getPublicVars() method). Note: This must also return
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:
Magento 1 – Where does Magento Set a Quote Item’s Price?
Whenever you load the cart page in Magento, the following code is run $cart->init(); $cart->save(); One side effect of this is that the prices for any items in the cart are updated if the …
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