一套PHP 面试题
1、 语句include和require都能把另外一个文件包含到当前文件中,它们的区别是___;为避免多此包含同一个文件,可以用语句_____来代替它们。
1、PHP程序执行到require()时,只会读取一次档案,故常放在程序开头,档案引入后PHP会将网页档重新编译,让引入档成为原先网页的一部分。 2、PHP程序执行到include()时,每次皆会读取档案,故常用于流程控制的区段,如条件判断或循环中。 3、require() :无条件包含,如果文件不存在,会报出一个fatal error.脚本停止执行 4、include() : 有条件包含,如果文件不存在,会给出一个 warning,但脚本会继续执行 5、推荐使用require_once()和include_once(),可以检测文件是否有重复包含。
2、表单中 get与post提交方法的区别?
POST方法比较适合用于发送一个保密的(比如信用卡号)或者比较大量的数据到服务器,但速度慢。而Get方法会将所要传输的数据附在网址后面,然后一起送达服务器,因此传送的数据量就会受到限制且不安全,但是执行效率却比 Post方法好。具体来说如下:
1、Get将表单中数据的按照variable=value的形式,添加到action所指向的URL后面,并且两者使用“?”连接,而各个变量之间使用“&”连接;Post是将表单中的数据放在form的数据体中,按照变量和值相对应的方式,传递到action所指向URL。
2、Get是不安全的,因为在传输过程,数据被放在请求的URL中,而如今现有的很多服务器、代理服务器或者用户代理都会将请求URL记录到日志文件中,然后放在某个地方,这样就可能会有一些隐私的信息被第三方看到。另外,用户也可以在浏览器上直接看到提交的数据,一些系统内部消息将会一同显示在用户面前。Post的所有操作对用户来说都是不可见的。
3、Get传输的数据量小,这主要是因为受URL长度限制;而Post可以传输大量的数据,所以在上传文件只能使用Post(当然还有一个原因,将在后面的提到)。
4、Get限制Form表单的数据集的值必须为ASCII字符;而Post支持整个ISO10646字符集。
5、Get是Form的默认方法。
3、foo()和@foo()之间有什么区别?
PHP 支持一个错误控制运算符:@。当将其放置在一个 PHP 表达式之前,该表达式可能产生的任何错误信息都被忽略掉。
注意: @ 运算符只对表达式有效。对新手来说一个简单的规则就是:如果能从某处得到值,就能在它前面加上 @ 运算符。
例如,可以把它放在变量,函数和include()调用,常量,等等之前。不能把它放在函数或类的定义之前,也不能用于条件结构例如 if 和 foreach 等。
4、PHP中===和==有什么区别?
===会比较两个变量的类型~~
而==只比较他们的值~~~
5、简述DIV元素和SPAN元素的区别
他们同为块级元素,但span又是内联对象
举例来说:
显示的效果是:第一例1
第一例1
而第二例2第二例2
显示的效果是:第二例2第二例2
你可以理解为div默认宽度是100%,而span无默认宽度
最明显的区别是:DIV是块元素,SPAN是内嵌元素。块元素相当于内嵌元素在前后各加一个
换行。其实,块元素和行内元素也不是一成不变的,只要给块元素定义display:inline,块元素就成了内嵌元素,同样地,给内嵌元素定义了display: block就成了块元素了。
6、Isset();empty();有什么区别?对于不同的数据的判断的结果?
$a=0;$a=’0′;$a=”;$a=false;$a=null;
Isset判断变量是否存在,如果存在则返回真,empty判断变量是否为空,如果为空则返回真。
Isset判断:true,true,true,true,false。
Empty判断:true,true,true,true,true。
7、请说明php中传值和传引用的区别?什么时候传值什么时候传引用?
传值:函数内对传送变量修改不影响被传变量的值(用传送值对函数的内的变量重新赋值)
引用:传送变量的引用,函数内的任何操作等同于对传送变量的操作,传送大型变量时效率高!
8、echo(),print(),print_r()的区别
echo是PHP语句, print和print_r是函数,语句没有返回值,函数可以有返回值(即便没有用)
print只能打印出简单类型变量的值(如int,string)
print_r可以打印出复杂类型变量的值(如数组,对象)
9、Sort() assort() ksort() 有什么区别? 它们分别在什么情况下使用?
sort(),根据数组中元素的值,以英文字母顺序排序,索引键会由0到n-1重新编号。主要是当数组索引键的值无关紧要时用来把数组排序。
assort(),PHP没有assort()函式,所以可能是asort()的笔误。asort(),对数组进行排序,数组的索引保持和单元的关联。主要用于对那些单元顺序很重要的结合数组进行排序。
ksort(),根据数组中索引键的值,以英文字母顺序排序,特别适合用于希望把索引键排序的关联数组。
10、Mysql_fetch_row() 和mysql_fetch_array()之间有什么区别?
这两个函数,返回的都是一个数组,区别就是第一个函数返回的数组是只包含值,我们只能$row[0],$row[1],这样以数组下标来读取数据,而MySQL_fetch_array()返回的数组既包含第一种,也包含键值对的形式,我们可以这样读取数据,(假如数据库的字段是 username,passwd):
$row['username'], $row['passwd']
11、mysql的存储引擎myisam和innodb的区别?
两种类型最主要的差别就是Innodb 支持事务处理与外键和行级锁。而MyISAM不支持.所以MyISAM往往就容易被人认为只适合在小项目中使用。
MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持。MyISAM类型的表强调的是性能,其执行数度比InnoDB类型更快,但是不提供事务支持,而InnoDB提供事务支持以及外部键等高级数据库功能。
12、抽象类和接口类有什么区别?
一、抽象类里面的方法可以有实现,但是接口里面的方法确是只能声明。
二、接口是设计的结果
抽象类是重构的结果
三、接口是特殊的抽象类,特殊在,接口中所有的方法都是抽象方法,接口中的属性只能为静态最终的常量
1.接口体现的是一种规范,抽象类体现的是模板式设计。
2.接口里的方法全部是抽象方法,抽象类里可以有方法实现。
3.接口里不可以定义静态方法,抽象类里可以。
4.接口里的变量全部为静态常量,抽象类里可以有普通变量。
5.接口里不可以有构造函数和初始化块,抽象类里可以有。
6.一个类可以实现多个接口,但只能继承一个抽象类。
13、Cookie和session的区别,禁止了cookie后session能正常使用吗?session的缺点是什么?session在服务器端是存在哪里的?是共有的还是私有的?
1、cookie数据存放在客户的浏览器上,session数据放在服务器上。 2、cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗 考虑到安全应当使用session。 3、session会在一定时间内保存在服务器上。当访问增多,会比较占用你服务器的性能 考虑到减轻服务器性能方面,应当使用COOKIE。 4、单个cookie保存的数据不能超过4K,很多浏览器都限制一个站点最多保存20个cookie。 sesion存在的前提是浏览器支持cookie,用户第一次访问网站时,cookie内没有session ID,然后服务器是把sesion ID写入了cookie,以后每次访问都从cookie获得的. 但如果该用户浏览器不支持cookie,那么每次请求都没有session ID,服务器就会 每次都认为用户是不同的用户,根本没法在服务器上保存用户之前一些操作结果.
14、->和::操作符的区别
类中 静态方法和静态属性的引用方法
例如
class Test{
public static $test = 1;
public static function test(){
}
}
可以不用实例化对象直接使用 Test::$test 来取得$test属性的值
静态方法调用也同理Test::test(); 直接调用静态方法test
在访问PHP类中的成员变量或方法时,如果被引用的变量或者方法被声明成const(定义常量)或者static(声明静态),那么就必须使用操作符::,反之如果被引用的变量或者方法没有被声明成const或者static,那么就必须使用操作符->。
另外,如果从类的内部访问const或者static变量或者方法,那么就必须使用自引用的self,反之如果从类的内部访问不为const或者static变量或者方法,那么就必须使用自引用的$this。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
