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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:24:57+00:00 2026-05-27T02:24:57+00:00

The PHP docs for join() and explode() say that the $glue and $delimiter must

  • 0

The PHP docs for join() and explode() say that the $glue and $delimiter must be strings. I tried this and it doesn’t throw any errors:

$glue = -8.5;
$delimiter = 0;
echo join( $glue, explode($delimiter, '1_0_1') ); // '1_-8.5_1'

So if I’m checking a $var that could be used as $glue or $delimiter, then is it safe to use is_string($var) || is_numeric($var)
as a condition OR are there times where that could be true but there’d be an error from the join() or explode()?

  • 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-27T02:24:58+00:00Added an answer on May 27, 2026 at 2:24 am

    You can just do type casting like this:

    // note join() is just an alias for implode. 
    // i like the symmetry of using implode/explode
    echo implode((string) $glue, explode((string) $delimiter, '1_0_1'));
    

    At any rate, it appears they were being converted anyway.

    Still, it would be good to use is_string() and is_numeric() to avoid a catchable fatal error if, say, an object was passed.

    if ((is_string($glue) || is_numeric($glue))
        && (is_string($delimiter) || is_numeric($delimiter))
    ) {
        // objects didn't pass the test, safe to type-cast
        echo implode((string) $glue, explode((string) $delimiter, '1_0_1'));
    }
    

    Edit

    Per ryanve’s suggestion, you could do this too:

    if (is_scalar($glue) && !is_bool($glue)) { // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP's explode function returns an array of strings split on some provided substring. It
I read on php docs that isset() is faster than property_exists() and we should
I read something about this on PHP docs , but it's not clear to
I tried Googling and browsing through PHP docs but I can't find a limit
I am writing some PHP. I have several classes that do not declare any
I'm working with the Fusion Chart Free API for PHP. The docs state that
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Hey guys, looked at the php docs and googled around, but no joy. This
The PHP docs are a bit fuzzy on this one, so I'm asking it
I don't see any in the PHP docs: http://www.php.net/manual/en/function.apc-store.php http://www.php.net/manual/en/function.apc-add.php Am I missing something

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.