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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:46:32+00:00 2026-05-23T18:46:32+00:00

I don’t think this question has been asked before (at least I couldn’t find

  • 0

I don’t think this question has been asked before (at least I couldn’t find it if it has…)

Recently I’ve started to work on a bigger project (at least more OOP(…by which I mean functions, classes, and objects)) than I usually use; However what variable type my function arguments should be is driving me crazy, for example:

<?php
function uberFunc($myArgument){
    switch($myArgument){
         //Stuff
    }
}
?>

And lets say, in this example, that $myArgument can only be a certain number of responses (ie it is not user created). For example, $myArgument might define how sql is ordered or which hash to use or some predefined list of values. Then the case statement turns $myArgument into some action (appending a mysql string or hashing a string a certain way).

tl;dr: Have argument for function that can only be one of a set of predefined values.

My question is: for these types of variables is it better to use a string literal (which will be decoded by a switch-case statement) or numbers (which would also be decoded by a switch-case statement)?

Currently I have been flip-flopping which is starting to create awkward code, so I want to chose one (string literals or numbers) and stick with it

Advantages (that I know of) to using string literals:

  • Readability
  • Direct insertation (ie, if your passing on a variable which determines how to organize your sql, you can do something like "SELECT * FROM main ORDER BY ".$myArgument

Advantages (that I know of) to using numbers:

  • Can be manipulated by math (if you ever need such a piece of code)
  • I believe they process marginally faster (not enough to make a difference though)
  • 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-23T18:46:33+00:00Added an answer on May 23, 2026 at 6:46 pm

    Actually, the only thing that I actually see that could be right is “readability”.

    About whether or not the variables can be “directly inserted” into your sql database, if you have
    "SELECT * FROM main ORDER BY ".$myArgument
    This will work whether or not $myArgument is a string or an integer. However, you should be using prepared statements (e.g. with PDO) which will prevent SQL injection as well as other advantages.

    Can be manipulated by math?

    echo "3" + "4"; // Outputs 7
    

    PHP will convert quoted strings to their numeric values when doing mathematical operations.

    As the other person said, the difference in speed is quite marginal.

    for ($i = 0; $i < 1000000; $i++) {
        $var = "3" + "4"; // takes 0.207326889038 seconds
    }
    
    for ($i = 0; $i < 1000000; $i++) {
        $var = 3 + 4; // takes 0.103585958481 seconds
    }
    

    Sure, it’s twice as long, but 0.1 seconds difference for 1 million iterations is nothing. Basically doing the first is stupid if you can do the second, however if it increases readability, as you can tell, it’s really not going to make much of a difference in speed.

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

Sidebar

Related Questions

Don't know if this has been asked before, so point me to another question
I don't know if this has been asked before, but what i'd like to
Don't know if this has been answered before. Have custom routes to users. If
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't know if this question is trivial or not. But after a couple
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know why but I can't find a solution to this. I have 3
Don't think this is a repost, difficult to search for the word between because
Don't let below code scare you away . The question is really simple, only
I don't understand where the extra bits are coming from in this article about

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.