Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
At the risk of seeming flip, PHP itself is frowned upon in OOP. If what you're doing works for you, go with it. – Ross Patterson Feb 2 '13 at 3:06
up vote 2 down vote accepted

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

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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