Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:04:29+00:00 2026-05-23T12:04:29+00:00

I wonder if I should write a function for a specific problem (e.g. function

  • 0

I wonder if I should write a function for a specific problem (e.g. function specific()) or if I should give this piece of code into one php script and call require 'specific.php' when needed?

The specific problem I’m talking is about processing a filled form requested via POST and then redirecting the browser because of the PRG (Post/Redirect/Get) pattern (which includes, that exit will be called and the code isn’t continued after the require respectively function call). The code for processing the request is needed in two scripts. Consider following code:

somePage.php

require 'process_form_fnc.php'; // for Variant 2

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
    // process filled form
    require 'process_form.php'; // Variant 1
    process_form_fnc();         // or Variant 2
}

Would you choose the function or the require variant (and why)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:04:30+00:00Added an answer on May 23, 2026 at 12:04 pm

    Using require to insert arbitrary code blocks at the current location is a bad hackish (even though not uncommon). I would always prefer to keep my code in functions.

    You can find similar discussions for C (#include arbitrary code snippets vs. functions), with almost the same arguments and an equally clear consensus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if there's some way of doing this, or even if it should
I have certain code that I want to optimize. It looks like this: function
I'm trying to write a xml schema that will validate this piece of xml:
I was looking into this ITE8712 watchdog timer demo code when I saw this:
I wonder why something like this wouldn't work (actually doesn't work): 4.php : <php
I wonder how I should use the GTree (from GLib) to store data? Every
I wonder what is the best C# data structure I should use to sort
wonder whether someone can help me with the following one... I have a struct
I wonder if someone knows if there is a pre-made solution for this: I
This function is called to serve each client in a new thread. in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.