How to add a method to an existing class in PHP?

Posted by sombe on Stack Overflow See other posts from Stack Overflow or by sombe
Published on 2010-06-10T05:45:11Z Indexed on 2010/06/10 5:52 UTC
Read the original article Hit count: 132

Filed under:
|
|
|

I'm using WordPress as a CMS, and I want to extend one of its classes without having to inherit from another class; i.e. I simply want to "add" more methods to that class:

class A {

    function do_a() {
       echo 'a';
    }
}

then:

function insert_this_function_into_class_A() {
    echo 'b';
}

(some way of inserting the latter into A class)

and:

A::insert_this_function_into_class_A();  # b

Is this even possible in tenacious PHP?

© Stack Overflow or respective owner

Related posts about php

Related posts about class