If I use array_walk inside a class function to call another function of the same class It gives me the following error – Warning: array_walk() [function.array-walk]: Unable to call test_print() – function does not exist in … So, how do I specify $this->test_print() while using array_walk(…
Tag: oop
PHP method chaining or fluent interface?
I am using PHP 5 and I’ve heard of a new featured in the object-oriented approach, called ‘method chaining’. What is it exactly? How do I implement it? Answer It’s rather simple, really. You have a series of mutator methods that all return the original (or other) object. That way, you …
PHP Store User Data without Sessions
Is there anyway to store users data such as userid, email, etc to be accessible from all pages of a website after they have logged in, but without using sessions or cookies? For example: after they login at login.php now, how do I access $currentUser from another page, such as index.php if I shouldn’t u…
could static members use nonstatic members and vice versa?
could i use nonstatic members inside a static method? eg. and vice versa that is to say use static members inside non-static methods? Answer From http://php.net/manual/en/language.oop5.static.php Declaring class properties or methods as static makes them accessible without needing an instantiation of the clas…
Is object-oriented PHP slow?
I used to use procedural-style PHP. Later, I used to create some classes. Later, I learned Zend Framework and started to program in OOP style. Now my programs are based on my own framework (with …
OO PHP direct member access [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 I always thought you should never set/get a member variable directly. E…
Why is the usage of $this in PHP necessary when referencing methods or variables in the same class?
I was explaining to a Java developer why his method call wasn’t working. He just needed to add $this->method_name(); He then asked me, “Why do I need to add $this to the method when it’s declared in the same class?” I didn’t really know how to answer. Maybe it’s because …
PHP equivalent of send and getattr?
If Ruby gets invited to a party and brings: .. and Python gets invited to the same party and brings: .. what does PHP have to bring to the party? Bonus question: If Ruby and Python got jealous of PHP’s party-favors, what English terms would they search for in PHP’s documentation in order to talk a…
Object-oriented-like structures in relational databases [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 Folks, For the n-th time in a row, i’m hitting the same old probl…