php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50801 Concatenate null values gives an empty string
Submitted: 2010-01-19 17:16 UTC Modified: 2010-01-19 17:20 UTC
From: public at proside dot fr Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.1 OS: WIN XP SP3
Private report: No CVE-ID: None
 [2010-01-19 17:16 UTC] public at proside dot fr
Description:
------------
When you concatenate only NULL values, you got an empty string

Reproduce code:
---------------
$a = NULL;
$b = NULL;
$c = $a . $b;

echo (is_null($c)) ? 'TRUE' : 'FALSE';


Expected result:
----------------
TRUE

Actual result:
--------------
FALSE

If you look : $c = ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-19 17:18 UTC] pajoye@php.net
php -r 'echo NULL;'
 [2010-01-19 17:20 UTC] rasmus@php.net
No, the '.' operator is defined as the string concatenation operator.  
Just like using it to concat numbers will cast the numbers to strings, 
using it to concat nulls will cast the nulls to strings and when you 
cast a null to a string you get an empty string.
 [2015-09-15 18:01 UTC] hablutzel1 at gmail dot com
Quoting: "when you cast a null to a string you get an empty string".

Is there any formal documentation on this?.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jun 06 07:01:26 2025 UTC