I come from c++, where one declares all assets to be included at the top of a file. That is what I have been doing with php as well. Lately I have been tempted to stray from this rule: I have a script file where I put functions I use throughout my projects, sort of like a library script. There are some functions included that require assets that no other function uses, and since one can put require_once statements all throughout one's scripts, I have been tempted to include assets at the beginning of those functions, to conserve resources when the script is running. Is this kind of thing frowned upon in OOP, or is that OK? I guess while I am at it, should I not be doing this at all because there is a purerer OOP approach to the kind of library scripts I have been creating?

  • 1
    At the risk of seeming flip, PHP itself is frowned upon in OOP. If what you're doing works for you, go with it. Feb 2, 2013 at 3:06

1 Answer 1


The best answer is that you should follow the conventions / recommendation's set out in the language's style guides.

For instance, Sun's Java Style Guide recommends that you declare static variables, then instance variables, then constructors and then methods; see http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141855.html#1852.

(This order probably makes sense for other OO languages too ... if there are no commonly used style guides specific to the language.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.