php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43846 Switch statement broken when using 'null' value
Submitted: 2008-01-14 21:21 UTC Modified: 2008-01-14 21:30 UTC
From: php_bug at jldupont dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
 [2008-01-14 21:21 UTC] php_bug at jldupont dot com
Description:
------------
The 'switch' statement does not correctly handle the case where the switch value === null.


Reproduce code:
---------------
The following code should show "null", "true", "false":

 function testSwitch( $v )
 {
  return $v;
 }

 function showResult( $r )
 {
  $v = testSwitch( $r );

  switch ($v)
  {
   case false:
    echo "false";
    break;
   case null:
    echo "null";
    break;
   case true:
    echo "true";
    break;
  }
   echo "\n<br/>";
 }

 showResult( null );
 showResult( true );
 showResult( false );


Expected result:
----------------
null
true
false


Actual result:
--------------
false
true
false


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-14 21:30 UTC] bjori@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 05 08:01:33 2025 UTC