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 3696230
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:42:50+00:00 2026-05-19T04:42:50+00:00

I recently answered this question: What are good reasons to use static methods in

  • 0

I recently answered this question:

What are good reasons to use static methods in PHP?

The first thing to come to mind, of course, was a singleton. With little exception, the other answerers provided the same singleton example. But that got me thinking… I don’t really ever use static methods or properties for anything besides creating singletons!

A brief search netted many tutorials on using static methods, almost all of which implement some variation of the same singleton class.

I’m really interested: What reason do we have to make static methods other than creating singletons (or other than just being lazy and wanting a global function)?

Does anyone have a pragmatic example of using a static method that could not be accomplished better using a dynamic design pattern? The example can be a singleton if that makes sense in it’s context, but I’m interested in other reasons besides the singleton-aspect of the solution.

  • 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-19T04:42:50+00:00Added an answer on May 19, 2026 at 4:42 am

    A factory pattern will normally use a static call as well; but it’s sensible to use static methods for any class mathod that has no dependencies on the instance properties or other instance methods, especially when they’re called regularly, for performance reasons.

    The logical place for the following method in PHPExcel is in the PHPExcel_Cell class, because it pertains directly to manipulating a cell address (any cell address, not just the address of a specific instance), but it has no dependency on the instance, so I declare it static.

    public static function stringFromColumnIndex($pColumnIndex = 0) {
        if ($pColumnIndex < 26) {
            return chr(65 + $pColumnIndex);
        } elseif ($pColumnIndex < 702) {
            return chr(64 + ($pColumnIndex / 26)).chr(65 + $pColumnIndex % 26);
        }
        return chr(64 + (($pColumnIndex - 26) / 676)).chr(65 + ((($pColumnIndex - 26) % 676) / 26)).chr(65 + $pColumnIndex % 26);
    }
    

    And this method isn’t particularly difficult to test

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

Sidebar

Related Questions

I recently answered this question how-to-call-user-defined-function-in-order-to-use-with-select-group-by-order-by My answer was to use an inline view
I've recently asked and had answered this question and it's stopped the issue of
I was asked this question in a job interview recently. I answered that I
Recently answered this question with a change to a core file: Approach on changing
I recently answered this question based on my experience: Counting rows before proceeding to
I recently posted a question which was answered by Bryan Watts, regarding generic repository
I know this question has probably been answered over 200 times and I have
Edit: While this question has been asked and answered before ( 1 ), (
Recently in a job interview I was asked this following question (for Java): Given:
I recently asked a question (and had it answered) here: jQuery Load JSON I

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.