Home  >  Article  >  Backend Development  >  大牛们美,php新手问几个面试题

大牛们美,php新手问几个面试题

WBOY
WBOYOriginal
2016-06-13 13:18:11809browse

大牛们好,php新手问几个面试题

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
1.
$a = 3;
$b = 2;
echo (int)$a/(int)$b

为什么输出是 1.5?


2.
How can you hide the fact that web pages are written in PHP?
a. By using AddType application/X-httpd-php asp
b. Specify all file names without any dot and extension
c. By using .htaccess diretive in Apeche
d. All of the above

3.
解释一下Using Register Globals。







------解决方案--------------------
1. 因为1)/是除法操作符,不是整除操作符 2)(int)操作符优先级高于/
所以 (int)$a/(int)$b = 3 / 2 = 1.5

2. 我选择d

3. Using Register Globals的场合,提交的变量可以直接通过 $变量名 使用。
但是存在安全问题,建议不要用Register Globals.
------解决方案--------------------
(int)作用于变量,而非整个表达式
(int)($a/$b);如此结果是1


2 事实上这些措施还不够,最好能重编译apache,改写web服务器输出头,隐藏开发语言是php的信息

3 是已经非常不推荐的功能了
------解决方案--------------------
楼上二位
在 C 里 (int)a/(int)b 可是等于 1 的噢
这道题就源于这里
考点是数据类型的自动变换,两个整型数相除结果为什么是浮点数
------解决方案--------------------
探讨
楼上二位
在 C 里 (int)a/(int)b 可是等于 1 的噢
这道题就源于这里
考点是数据类型的自动变换,两个整型数相除结果为什么是浮点数

------解决方案--------------------
探讨

2 事实上这些措施还不够,最好能重编译apache,改写web服务器输出头,隐藏开发语言是php的信息


------解决方案--------------------
好像说到没啥意义的地方去了。或者说根本没必要这么去做


数据类型
根源还是在于php转换数据类型太容易了,hoho

强类型的语言,一般都会以a、b当中,精度更高的作为结果返回
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn