Home php教程 php手册 php面试需要掌握的基础题目锦集

php面试需要掌握的基础题目锦集

Jun 21, 2016 am 08:47 AM
include php require session

1.session与cookie的区别?

答:session:储存用户访问的全局唯一变量,存储在服务器上的php指定的目录中的(session_dir)的位置进行的存放

cookie:用来存储连续訪問一个頁面时所使用,是存储在客户端,对于Cookie来说是存储在用户WIN的Temp目录中的。

两者都可通过时间来设置时间长短

2.如何修改SESSION的生存时间

答:方法1:将php.ini中的session.gc_maxlifetime设置为9999重启apache

方法2:$savePath = "./session_save_dir/";

$lifeTime = 小时 * 秒;

session_save_path($savePath);

session_set_cookie_params($lifeTime);

session_start();

方法3:setcookie() and session_set_cookie_params($lifeTime);

3.PHP是什么?

答:PHP是一个基于服务端来创建动态网站的脚本语言,您可以用PHP和HTML生成网站主页

4.语句include和require的区别是什么?为避免多次包含同一文件,可用(?)语句代替它们? (2分)

答:require->require是无条件包含也就是如果一个流程里加入require,无论条件成立与否都会先执行require

include->include有返回值,而require没有(可能因为如此require的速度比include快)

注意:包含文件不存在或者语法错误的时候require是致命的,include不是

5.谈谈asp,php,jsp的优缺点

答:ASP全名Active Server Pages,是一个WEB服务器端的开发环境, 利用它可以产生和运

答:行动态的、交互的、高性能的WEB服务应用程序。ASP采用脚本语言VB Script(Java script

)作为自己的开发语言。

   PHP是一种跨平台的服务器端的嵌入式脚本语言. 它大量地借用C,Java和Perl语言的语法

, 并耦合PHP自己的特性,使WEB开发者能够快速地写出动态生成页面.它支持目前绝大多数数

据库。还有一点,PHP是完全免费的,不用花钱,你可以从PHP官方站点(http://www.php.ne

t)自由下载。而且你可以不受限制地获得源码,甚至可以从中加进你自己需要的特色。

   JSP 是Sun公司推出的新一代站点开发语言,他完全解决了目前ASP,PHP的一个通病--

脚本级执行(据说PHP4 也已经在Zend 的支持下,实现编译运行).Sun 公司借助自己在Jav

a 上的不凡造诣,将Java 从Java 应用程序 和 Java Applet 之外,又有新的硕果,就是Js

p--Java Server Page。Jsp 可以在Serverlet和JavaBean的支持下,完成功能强大的站点

程序。

   三者都提供在 HTML 代码中混合某种程序代码、由语言引擎解释执行程序代码的能力。

但JSP代码被编译成 Servlet 并由 Java 虚拟机解释执行,这种编译操作仅在对 JSP 页面的

第一次请求时发生。在 ASP 、PHP、JSP 环境下, HTML 代码主要负责描述信息的显示样式

,而程序代码则用来描述处理逻辑。普通的 HTML 页面只依赖于 Web 服务器,而 ASP 、PH

P、JSP 页面需要附加的语言引擎分析和执行程序代码。程序代码的执行结果被重新嵌入到

HTML 代码中,然后一起发送给浏览器。 ASP 、PHP、 JSP三者都是面向 Web 服务器的技术

,客户端浏览器不需要任何附加的软件支持。

5.谈谈对mvc的理解,并列举常用的框架?

答:MVC是一个设计模式,它强制性的使应用程序的输入、处理和输出分开。使用MVC应用程序被分成三个核心部件:模型、视图、控制器。它们各自处理自己的任务。

视图是用户看到并与之交互的界面。

模型表示企业数据和业务规则。

控制器接受用户的输入并调用模型和视图去完成用户的需求。

MVC的优点:低耦合性、高重用性和可适用性、较低的生命周期成本、快速的部署、可维护性、可扩展性,有利于软件工程化管理

MVC的缺点:没有明确的定义,完全理解MVC并不容易。不适合小型规模的应用程序。

Smarty,zend framework,thinkphp,PHPlib Template

6.php如何抛出异常?

答:使用try...catch,异常的代码放在try代码块内,如果没有触发异常,则代码继续执行,如果异常被触发,就会抛出一个异常。

Catch代码块捕获异常,并创建一个包含异常信息的对象。$e->getMessage(),输出异常的错误信息。

7.谈谈php中传值和引用的区别?

答:按值传递:函数范围内对值的任何改变在函数外部都会被忽略

按引用传递:函数范围内对值的任何改变在函数外部也能反映出这些修改

优缺点:按值传递时,php必须复制值。特别是对于大型的字符串和对象来说,这将会是一个代价很大的操作。
按引用传递则不需要复制值,对于性能提高很有好处。

8,php中include与require的区别?

答:一、PHP在遇到include时就必须重新解释一次,如果在同一个页面出现10次include,它便会重新解释10次。PHP遇到require时,不管在同一个php网页中出现几 次require,PHP只会解释一次而已。

二、Require执行效率比include高。

三、Require包含进来的内容被当成当前文件的一个组成部分,所以当包含进来的文件有语法错误或者文件不存在的时候,那个PHP脚本都不再执行。Include函数相当 于指定这个文件的路径,当被包含的文件有错时不会影响到本身的程序执行。

四、Include可以进行判断是否包含,而require则是不管任何情况都包含进来

9.表单中 get与post提交方法的区别?

答:get是发送请求HTTP协议通过url参数传递进行接收,

post是实体数据,可以通过表单提交大量信息.

12.echo(),print(),print_r()的区别(3分)

答:echo是PHP语句, print和print_r是函数,语句没有返回值,函数可以有返回值(即便没有用)

print() 只能打印出简单类型变量的值(如int,string)

print_r() 可以打印出复杂类型变量的值(如数组,对象)

echo 输出一个或者多个字符串

11.数据库中的事务是什么?

答:事务(transaction)是作为一个单元的一组有序的数据库操作。如果组中的所有操作都成功,则认为事务成功,即使只有一个操作失败,事务也不成功。如果所有操作完成,

事务则提交,其修改将作用于所有其他数据库进程。如果一个操作失败,则事务将回滚,该事务所有操作的影响都将取消。

12.服务器apache两种工作模式及区别

答:1.prefork.c模块(一个非线程型的、预派生的MPM)
prefork MPM 使用多个子进程,每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接。在大多数平台上,Prefork MPM在效率上要比Worker MPM 要高,但是内存使用大得多。
2. worker.c模块(支持混合的多线程多进程的多路处理模块)
worker MPM 使用多个子进程,每个子进程有多个线程。





Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

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: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

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 in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

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 vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

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 and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

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 vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

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.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles