Why do some hooks not work inside class context?

Sometimes certain hooks need to be fired at certain times. Example, some hooks need to be fired upon init. Add this to your __construct() add_action(‘init’, array(&$this, ‘init’)); Then add this function, which will contain all hooks that need to be fired upon init. public function init(){ add_action(‘hook_name’, array(&$this, ‘your_method_name’)); add_action(‘hook_name’, array(&$this, ‘your_method_name’)); add_action(‘hook_name’, array(&$this, ‘your_method_name’)); … Read more

Registering Class methods as hook callbacks

If I need to register an action inside the class itself would it work with array($this, ‘bar’)? Yes, it works. $thisDocs is referring to the concrete instance needed for the callback. That’s exactly like the $foo example you give. It’s just that $this is bit more special, but it represents basically the same and it … Read more

Should all plugins be encapsulated in a Class?

When developing a plugin should the functions be grouped together into a Class to avoid namespace conflicts? Yes, but that’s only one of the minor arguments. In-fact that’s not the “true” nature of a class in OOAD. Does using classes create performance overheads for PHP? No, not notably. Bad design and/or bad written code or … Read more

Using OOP in themes

I can understand your confusion based on the example you provided. That’s really a poor way to use a class … and just because a class is used, doesn’t make a system OOP. In the case of Hybrid, they’re just using a class to namespace their functions. Considering Hybrid is a theme framework, this is … Read more

How to remove a filter that is an anonymous object?

That’s a very good question. It goes down to the dark heart of the plugin API and best programming practices. For the following answer I created a simple plugin to illustrate the problem with easy to read code. <?php # -*- coding: utf-8 -*- /* Plugin Name: Anonymous OOP Action */ if ( ! class_exists( … Read more

C++ equivalent of java’s instanceof

Try using: This requires your compiler to have rtti support enabled. EDIT: I’ve had some good comments on this answer! Every time you need to use a dynamic_cast (or instanceof) you’d better ask yourself whether it’s a necessary thing. It’s generally a sign of poor design. Typical workarounds is putting the special behaviour for the … Read more

How can I design a class named allergy?

1 requirement: design a class named allergy that provides information about the allergy of a patient. e.g. who reported the allergy(patient/doctor/relative), different symptoms of the allergy that are detected, severity, method that returns when was that allergy detected in that patient. I am thinking of something like this: Is this a good design of the … Read more

What does the variable $this mean in PHP?

It’s a reference to the current object, it’s most commonly used in object oriented code. Reference: http://www.php.net/manual/en/language.oop5.basic.php Primer: http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html Example: This stores the ‘Jack’ string as a property of the object created.

Error: invalid use of member in static member function

I have two classes, and this is the header of one of them: I am calling Wrapper::set_screen(screen) from another file and I get this error: I also get a similar error for the definition of every single function on Wrapper.cpp, for example: On compile: I know it’s related to the class being static and thus … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)