ببینید، گزارش Bug صرفاً به معنای وجود خطا در طراحی و نحوه کاربرده. من هم بعنوان SPL Problem گزارش کردم و گفتم این رفتار، اون چیزی که اغلب برنامه نویسان انتظار دارن نیست و ممکنه منجر به باگهای امنیتی توی برنامه های کاربران بشه. نه اینکه خودش یک باگه. توصیه هم کردم که switch لااقل مثل بقیه زبانهای Loose Type از strong type comparison استفاده کنه یا یک پارامتر دوم بهش اضافه کنن که هروقت کاربر خواست، بتونه نحوه عملکردش رو تنظیم کنه. اینم متن گزارشیه که فرستادم:
[2013-12-26 06:18 UTC] mmshfe at gmail dot com
Description:
------------
As mentioned in docs, switch statement is a loose type comparison tool. But this may be lead to a serious bug in user products. It would be really better to force it to use strong type comparison (or have an option such as an optional 2nd argument let the users to do so). In the real world, we have no other loose type languages that behaves like this. For example, in JavaScript, the result is fine. I mean, although being a loose type language is a good feature for PHP in overall; It should not be led to unexpected results those not shown in any other language (even the other loose type ones).
Test script:
---------------
$v = 0;
switch($v) {
case 'hello':
echo 'Hello';
break;
case 'Goodbye':
echo 'Goodbye';
break;
default:
echo 'Error';
break;
}
Expected result:
----------------
Error
Actual result:
--------------
Hello
--------------
[2013-12-26 06:29 UTC] mmshfe at gmail dot com
I really now the process flow. It uses if, elseif, else statements like this:
if($v == 'hello') {
echo 'Hello';
}
elseif($v == 'Goodbye') {
echo 'Goodbye';
}
else {
echo 'Error';
}
And 'hello' is converted to integer (with intval('hello') or anything similar) and because it does not contain an integer value at the beginning, it uses the default integer value (zero) and so, the first case becomes true. All I want to say is that this behavior is incorrect because approximately always it's not the behavior that the developer expected.