getButterfly
Resume

NAVIGATION

ATTRIBUTION

getButterfly
Dublin, Ireland

All Content Copyright ©2019
getButterfly

OOP In PHP (Object Oriented Programming in PHP)

This is a basic introduction on how to use OOP – Object Oriented Programming in PHP, as requested by a friend.

Declaring a Class

class myClass {
    // Class contents go here
}

Instantiating an Object

$myClassInst = new myClass();

OOP Class Inheritance

class a {
    function test() {
        echo "a::test called";
    }

    function func() {
        echo "a::func called";
    }
}

class b extends a {
    function test() {
        echo "b::test called";
    }
}

class c extends b {
    function test() {
        parent::test();
    }
}

class d extends c {
    function test() {
        b::test();
    }
}

$a = new a();
$b = new b();
$c = new c();
$d = new d();

$a->test(); // Outputs "a::test called"
$b->test(); // Outputs "b::test called"
$b->func(); // Outputs "a::func called"
$c->test(); // Outputs "b::test called"
$d->test(); // Outputs "b::test called"

Added by Ciprian on Sunday, January 14, 2018 in Blog

Do you want better SEO? More traffic? More conversions? More growth? We help companies exponentially grow their traffic and conversions, while outranking their competitors. With more than 10 years of experience, we’ve learned what is valuable to our clients.
SEO Dublin | SEO Malta

My Battle Tested Recommendations

Jetpack
Dreamhost
WordPress.com
CodeCanyon
SEMrush

Disclaimer: These recommendations contain affiliate links.


Privacy Policy