是我的PHP解释器疯了,或者我是一个谁...? [英] is my php interpreter going crazy, or am i the one who is...?

查看:118
本文介绍了是我的PHP解释器疯了,或者我是一个谁...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继续遇到真正奇怪的行为编码php。以下是一个示例:

I'm continuing to run into really weird behaviour coding php. Here is an example:

<?php 
date_default_timezone_set("Europe/Berlin");
$interval1 = (int) 336000;
$interval2 = (int) 1459200;
$interval3 = (int) 17403000;
$interval4 = (int) 43205760;
$interval5 = (int) 84299520;
$week =  (int) 604800;
?>

当我运行这个代码,我得到一个意外的T_INT_CAST第8行错误
WTF?前5个施法完全正常。当我不投射任何东西,前5个表达式导致一个整数,最后一个在字符串中。

When I run this code, i get an "unexpected T_INT_CAST on line 8 error" WTF?!! the first 5 casts work perfectly fine. When i don't cast anything, the first 5 expressions result in a integer, the last one in a string. I noticed this while comparing values and obviously got wrong results.

这是十六进制编辑器输出(如注释中所要求的):

Here is the hex editor output (as requested in a comment):

00000000: 3C 3F 70 68 70 20 0A 64  61 74 65 5F 64 65 66 61 
00000010: 75 6C 74 5F 74 69 6D 65  7A 6F 6E 65 5F 73 65 74 
00000020: 28 22 45 75 72 6F 70 65  2F 42 65 72 6C 69 6E 22 
00000030: 29 3B 0A 24 69 6E 74 65  72 76 61 6C 31 20 3D 20 
00000040: 28 69 6E 74 29 20 33 33  36 30 30 30 3B 20 2F 2F 
00000050: 74 65 73 74 20 69 6E 74  65 72 76 61 6C 20 66 72 
00000060: 6F 6D 20 68 74 74 70 3A  2F 2F 65 63 6B 71 75 61 
00000070: 72 74 65 72 73 2E 63 6F  6D 2F 6D 6F 65 74 65 72 
00000080: 77 6F 6C 66 2F 64 69 61  67 72 61 6D 6D 31 2E 68 
00000090: 74 6D 6C 0A 24 69 6E 74  65 72 76 61 6C 32 20 3D 
000000A0: 20 28 69 6E 74 29 20 31  34 35 39 32 30 30 3B 0A 
000000B0: 24 69 6E 74 65 72 76 61  6C 33 20 3D 20 28 69 6E 
000000C0: 74 29 20 31 37 34 30 33  30 30 30 3B 0A 24 69 6E 
000000D0: 74 65 72 76 61 6C 34 20  3D 20 28 69 6E 74 29 20 
000000E0: 34 33 32 30 35 37 36 30  3B 0A 24 69 6E 74 65 72 
000000F0: 76 61 6C 35 20 3D 20 28  69 6E 74 29 38 34 32 39 
00000100: 39 35 32 30 3B 0A 24 77  65 65 6B 20 3D 20 A0 69 
00000110: 6E 74 76 61 6C 28 36 30  34 38 30 30 29 3B


推荐答案

十六进制编辑器在你的php代码中有不间断的空格就在intval之前/(int)cast:(第二个空格)

As you can see from the hex editor in your php code there is non-breaking space just before intval / (int) casting: (the second space)

00000100:39 35 32 30 3B 0A 24 77 65 65 6B 20 3D 20 A0 69

00000100: 39 35 32 30 3B 0A 24 77 65 65 6B 20 3D 20A069

摆脱它,你的代码应该工作。

get rid of it and your code should work.

这篇关于是我的PHP解释器疯了,或者我是一个谁...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆