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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:56:43+00:00 2026-05-26T07:56:43+00:00

Is it possible to define a function argument as multiple possible types? For example,

  • 0

Is it possible to define a function argument as multiple possible types? For example, a function may take a string or an integer to accomplish something. Is it possible to somehow define it like this?

    function something(int|string $token) {}

Or is only one type per argument supported?

(mind you, I know I can filter input later on, I just like to have my arguments typed)

  • 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-26T07:56:44+00:00Added an answer on May 26, 2026 at 7:56 am

    The best you can do is called Type Hinting and is explained here:

    http://php.net/manual/en/language.oop5.typehinting.php

    In particular, you can hint a class type or an array type, but (as the manual says) “Traditional type hinting with int and string isn’t supported.” So I guess that what you are trying to accomplish is not possible at this level.

    However, you can create your own wrappers, etc. There are probably a thousand ways to handle this.

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

Sidebar

Related Questions

Is it possible to define function with argument list of variable length? I know
Is it possible to define a function which will make the argument refer to
One can easily define a function that accepts a 1d array argument like this:
Is it possible to define a method like below to receive $id? public function
Lets take qsort()'s comparison callback function as an example int (*compar)(const void *, const
is it not possible to define a static const array? i would like to
I would like the below function to be more flexible and accept multiple callbacks
Is it possible to pass a function pointer as an argument to a function
Is that possible to define a function without referencing to self this way? def
In PHP it is possible to specify argument types although they call it type

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.