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

  • SEARCH
  • Home
  • 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 986123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:16:11+00:00 2026-05-16T05:16:11+00:00

I am writing some PHP code to create PDFs using the FPDF library. And

  • 0

I am writing some PHP code to create PDFs using the FPDF library. And I basically use the same 4 lines of code to print every line of the document. I was wondering which is more efficient, repeating these 4 lines over and over, or would making it into a function be better? I’m curious because it feels like a function would have a larger overhead becuse the function would only be 4 lines long.

The code I am questioning looks like this:

$pdf->checkIfPageBreakNeeded($lineheight * 2, true);
$text = ' label';
$pdf->MultiCell(0, $lineheight, $text, 1, 'L', 1);
$text = $valueFromForm;
$pdf->MultiCell(0, $lineheight, $text, 1, 'L');
$pdf->Ln();
  • 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-16T05:16:12+00:00Added an answer on May 16, 2026 at 5:16 am

    This should answer it:
    http://en.wikipedia.org/wiki/Don%27t_repeat_yourself
    and
    http://www.codinghorror.com/blog/2007/03/curlys-law-do-one-thing.html

    Curly’s Law, Do One Thing, is
    reflected in several core principles
    of modern software development:

    • Don’t Repeat Yourself

      If you have more than one way to express the same thing, at some point
      the two or three different
      representations will most likely fall
      out of step with each other. Even if
      they don’t, you’re guaranteeing
      yourself the headache of maintaining
      them in parallel whenever a change
      occurs. And change will occur. Don’t
      repeat yourself is important if you
      want flexible and maintainable
      software.

    • Once and Only Once

      Each and every declaration of behavior should occur once, and only
      once. This is one of the main goals,
      if not the main goal, when refactoring
      code. The design goal is to eliminate
      duplicated declarations of behavior,
      typically by merging them or replacing
      multiple similar implementations with
      a unifying abstraction.

    • Single Point of Truth

      Repetition leads to inconsistency and code that is subtly
      broken, because you changed only some
      repetitions when you needed to change
      all of them. Often, it also means that
      you haven’t properly thought through
      the organization of your code. Any
      time you see duplicate code, that’s a
      danger sign. Complexity is a cost;
      don’t pay it twice.

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

Sidebar

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.