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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:32:54+00:00 2026-06-05T12:32:54+00:00

Since PHP treats them equally in string operations and output, I would like to

  • 0

Since PHP treats them equally in string operations and output, I would like to know what is the best practice, to assign/concatenate a null value or an empty string:

$lang = 'lang';
$suffix = null;
$lang .= $suffix;

or

$desc = 'name';
$suffix = '';
$desc .= $suffix;

This can also be the case for inline conditions:

<div class="item<?= $is_selected ? ' selected' : null ?>"></div>

or

<div class="item<?= $is_selected ? ' selected' : '' ?>"></div>

I know it won’t affect the overall performance, but could it compare to using double or single quotes?

  • 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-06-05T12:32:56+00:00Added an answer on June 5, 2026 at 12:32 pm
    > php --version
    PHP 5.3.12 with Suhosin-Patch (cli) (built: May  9 2012 11:44:31) 
    Copyright (c) 1997-2012 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
        with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
    
    php > $start = microtime(true); for( $i = 0; $i < 1000000; ++$i ) { $str = 'foo'; $str .= null; } printf('%.5f', microtime(true) - $start);
    0.15258
    php > $start = microtime(true); for( $i = 0; $i < 1000000; ++$i ) { $str = 'foo'; $str .= ''; } printf('%.5f', microtime(true) - $start);
    0.11397
    

    Ran this a few times, and got very similar results every time.

    Conclusion:

    • Appending an empty string to a string is very slightly faster than appending null to an empty string.
    • Unless you are doing this inside a loop with billions of iterations, it doesn’t matter from a performance standpoint, so use the one that makes better semantic sense.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since POSIX regular expressions (ereg) are deprecated since PHP 5.3.0, I'd like to know
Since PHP has no custom-class type-casting, how would I go about doing the PHP
I don't know how php.ini was configured since I don't have access to it.
This kind of code would normally work in PHP, but since the scope is
Since PHP is a dynamic language what's the best way of checking to see
Since I'm not an Php programmer I have to ask you, I have to
It's been a while since I've installed PHP for Windows, but every guide I've
I am currently translating my PHP application using gettext with POEdit. Since I respect
Since PHP code will run just fine even if it's riddled with warnings and
I have this function that I wrote that is abysmally slow since php does

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.