Can you code a class function outside of a class in PHP?

In C++, I code this way:

//foo.h    
class cBar
{
    void foobar();
}


//foo.cpp
void cBar::foobar()
{
    //Code
}

I tried to do this on PHP but the parser would complain. PHP's documentation also doesn't help. Can this be done in PHP?

Answers


No. You need to including all your function definitions inside the class block. If defining your functions in a separate structure makes you feel better you could use an interface.

interface iBar
{
    function foobar();
}


class cBar implements iBar
{
    function foobar()
    {
        //Code
    }
}

I'd suggest just getting used to coding in a new way. It's easy to code consistantly within a single language, but I think you are fighting a loosing battle if you want to do the same across languages.


Need Your Help

Converting regex to account for international characters

php regex internationalization

I currently have the following regex for validating on inputting a company name into a form:

Pass GET parameters with Ruby Curb

ruby-on-rails ruby rest curl libcurl

I'm trying to use Curb (curb.rubyforge.org) to call a RESTful API that needs parameters supplied in a get request.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.