Viewing 4 posts - 1 through 4 (of 4 total)
  • Where should I put my PHP functions?
  • PJay
    Free Member

    I'm slowly trying to teach myself PHP and am currently looking at functions. I've very little programming experience but as a once BBC Basic user I'm used to putting funcions and procedures out of the way at the end of the code. PHP allows this but the examples in the book place them at the start of the code; during a very brief flirtation with C++ I learnt that its functions needed to be at the start of the code as calling a function before it had been defined caused an error.

    Since I'm starting out afresh, as it were, would it be considered good practive in PHP (and general programming) terms to put my functions at the start of the code therefore defining them before they're called?

    IanMunro
    Free Member

    I'd say it's standard practice to put functions at the top in most languages.
    Others may disagree, but they're wrong 🙂

    woody2000
    Full Member

    Can you specify them in a separate file and use includes? That way you only need to define them once, and you can use them in any subsequent pages by just including the function file? Or does PHP not allow that

    Flaperon
    Full Member

    What woody2000 says. Make sure you understand the difference between include() and require() though.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Where should I put my PHP functions?’ is closed to new replies.