开发者

PHP die() vs. echo

Can anyone please tell me why line 1 works (returns 35434), but line 2 doesn't (开发者_高级运维returns blank)?

  1. echo $_FILES['userfile']['size'];
  2. die ($_FILES['userfile']['size']);

Thanks!


die is equivalent to exit and you'll notice that exit takes either an integer or a string as an argument. In the case you pass an integer, then the program exits and returns that integer as its exit code.

$_FILES['userfile']['size'] is an integer, not a string, so instead of outputting the message to the screen, it returns the size as the return code of the program.

A simple solution is to concatenate to an empty string to let the PHP compiler you want a string instead of an integer:

die('' . $_FILES['userfile']['size']);


I answered this a few hours ago, anyway the other answers are right.

As a workaround (if you need to do that), casting the integer to a string will do the trick:

die(strval($_FILES['userfile']['size'])); // or
die((string) $_FILES['userfile']['size']);


die() only prints strings. (See manual) If you add some text in there it will work, for some reason. ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜