Debian Bug report logs - #734129
switch($X){case 'Y':trigger_error("can you believe \$X is NOT Y but Z"); }

version graph

Package: php5-cli; Maintainer for php5-cli is (unknown);

Reported by: jidanni@jidanni.org

Date: Sat, 4 Jan 2014 01:48:02 UTC

Severity: important

Found in version php5/5.5.7+dfsg-2

Done: jidanni@jidanni.org

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>:
Bug#734129; Package php5-cli. (Sat, 04 Jan 2014 01:48:07 GMT) (full text, mbox, link).


Acknowledgement sent to jidanni@jidanni.org:
New Bug report received and forwarded. Copy sent to Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>. (Sat, 04 Jan 2014 01:48:07 GMT) (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: jidanni@jidanni.org
To: submit@bugs.debian.org
Subject: switch($X){case 'Y':trigger_error("can you believe \$X is NOT Y but Z"); }
Date: Sat, 04 Jan 2014 09:45:14 +0800
Package: php5-cli
Version: 5.5.7+dfsg-2
Severity: important

$ cat n.php
<?php
$wgSitename='ABJ';
$wgSitename=0;
switch($wgSitename){case 'ABJ':trigger_error("can you believe \$wgSitename is $wgSitename and not ABJ?!",E_USER_WARNING);}
$wgSitename=0;
$wgSitename='ABJ';
switch($wgSitename){case 0:trigger_error("can you believe \$wgSitename is $wgSitename and not 0?!",E_USER_WARNING);}
$ php n.php
PHP Warning:  can you believe $wgSitename is 0 and not ABJ?! in /mnt/usb/cf/n.php on line 4
PHP Warning:  can you believe $wgSitename is ABJ and not 0?! in /mnt/usb/cf/n.php on line 7

What in the world is going on?



Reply sent to jidanni@jidanni.org:
You have taken responsibility. (Sat, 04 Jan 2014 02:09:10 GMT) (full text, mbox, link).


Notification sent to jidanni@jidanni.org:
Bug acknowledged by developer. (Sat, 04 Jan 2014 02:09:10 GMT) (full text, mbox, link).


Message #10 received at 734129-done@bugs.debian.org (full text, mbox, reply):

From: jidanni@jidanni.org
To: daniel@nadir-seen-fire.com
Cc: mediawiki-l@lists.wikimedia.org, 734129-done@bugs.debian.org
Subject: Re: switch($X){case 'Y':trigger_error("can you believe \$X is NOT Y but Z"); }
Date: Sat, 04 Jan 2014 10:07:16 +0800
OK I see,
http://www.php.net/manual/en/control-structures.switch.php#86911
http://www.php.net/manual/en/control-structures.switch.php#97112
http://www.php.net/manual/en/control-structures.switch.php#84150
How awful. No wonder people write
http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/



Message #11 received at 734129-done@bugs.debian.org (full text, mbox, reply):

From: Bob Proulx <bob@proulx.com>
To: 734129-submitter@bugs.debian.org, 734129-done@bugs.debian.org
Subject: Re: Bug#734129: switch($X){case 'Y':trigger_error("can you believe \$X is NOT Y but Z"); }
Date: Fri, 3 Jan 2014 19:10:55 -0700
[Message part 1 (text/plain, inline)]
jidanni@jidanni.org wrote:
> $ cat n.php
> <?php
> $wgSitename='ABJ';
> $wgSitename=0;
> switch($wgSitename){case 'ABJ':trigger_error("can you believe \$wgSitename is $wgSitename and not ABJ?!",E_USER_WARNING);}
> $wgSitename=0;
> $wgSitename='ABJ';
> switch($wgSitename){case 0:trigger_error("can you believe \$wgSitename is $wgSitename and not 0?!",E_USER_WARNING);}
> $ php n.php
> PHP Warning:  can you believe $wgSitename is 0 and not ABJ?! in /mnt/usb/cf/n.php on line 4
> PHP Warning:  can you believe $wgSitename is ABJ and not 0?! in /mnt/usb/cf/n.php on line 7
> 
> What in the world is going on?

You have a bug in your php code.  You are comparing strings and
numbers together.  Never do that.  That is a well known PHP design
choice (and mis-feature).  PHP programmers must understand how types
are automatically converted.  Sure it is a bad design but that is just
the way PHP is.

Specifically PHP switch statements use "==" comparison not "==="
comparison and "==" comparison is poorly designed.

  http://php.net/manual/en/control-structures.switch.php

And also:

  http://docs.php.net/manual/en/language.operators.comparison.php#language.operators.comparison

There is an explicit example of this in that latter reference.

  <?php
  var_dump(0 == "a"); // 0 == 0 -> true
  var_dump("1" == "01"); // 1 == 1 -> true
  var_dump("10" == "1e1"); // 10 == 10 -> true
  var_dump(100 == "1e2"); // 100 == 100 -> true

  switch ("a") {
  case 0:
      echo "0";
      break;
  case "a": // never reached because "a" is already matched with 0
      echo "a";
      break;
  }
  ?>

This type of question should be referred to a PHP user mailing list
for answering and not to the bug tracking system.  The BTS is for
tracking bugs in packages not.  You are not reporting a bug in php but
are instead just asking a question about php.

Bob
[signature.asc (application/pgp-signature, inline)]

Message sent on to jidanni@jidanni.org:
Bug#734129. (Sat, 04 Jan 2014 02:15:04 GMT) (full text, mbox, link).


Information stored :
Bug#734129; Package php5-cli. (Sat, 04 Jan 2014 02:27:07 GMT) (full text, mbox, link).


Acknowledgement sent to jidanni@jidanni.org:
Extra info received and filed, but not forwarded. (Sat, 04 Jan 2014 02:27:07 GMT) (full text, mbox, link).


Message #19 received at 734129-quiet@bugs.debian.org (full text, mbox, reply):

From: jidanni@jidanni.org
To: bob@proulx.com
Cc: 734129-quiet@bugs.debian.org
Subject: Re: Bug#734129: switch($X){case 'Y':trigger_error("can you believe \$X is NOT Y but Z"); }
Date: Sat, 04 Jan 2014 10:25:05 +0800
Yes it is all my fault. Sorry.



Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Sat, 01 Feb 2014 07:27:55 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sun Jul 2 02:46:40 2023; Machine Name: buxtehude

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.