KaiserJohaan
KaiserJohaan

Reputation: 9240

php - separate class method declarations and defintions?

I'm comming from C++ and from all I've read in the manual and code examples, none seem to separate a class method declaration from its definition. Is this not possible in PHP? Dosn't this lead to very hard-to-read and cluttery interfaces?

Thanks

EDIT: I want something like this:

class MyClass
{
    public function Foo();

};

MyClass::Foo()
{
    echo "O-hoy!";
}

Upvotes: 2

Views: 222

Answers (2)

Bart Friederichs
Bart Friederichs

Reputation: 33521

When not using interfaces, you are right. Like in Java, the class definition is the declaration. However, (also like Java), you have the interface available that you can use:

From the documentation:

interface iTemplate
{
    public function setVariable($name, $var);
    public function getHtml($template);
}

// Implement the interface
// This will work
class Template implements iTemplate
{
    private $vars = array();
    ...
}

it is perfectly legal to put them in different files. The class definition though, will always be in one file. You cannot use the partial keyword as you can in C#.

Upvotes: 2

erenon
erenon

Reputation: 19118

This concept is not necessary in PHP. If you want to get a clean interface, you might define one. http://php.net/manual/en/language.oop5.interfaces.php

Upvotes: 1

Related Questions