Home Backend Development PHP Tutorial 《php与MySQL Web开发》-读书笔记一

《php与MySQL Web开发》-读书笔记一

Jun 23, 2016 pm 01:37 PM

1 require和include函数
几乎相同
唯一区别:require()函数会给出一个致命错误,而include()只给一个警告。
变种require_once和include_once?
防止错误的引入同样的函数库两次。出现重复定义的错误。而原版本的运行速度较快。
2 require用法
php不会查看require函数中文件的扩展名。使用require()语句载入文件page.html,文件内任何php命令都会被处理。但php代码放到php标记之间才会被处理成php代码。否则,代码将被视为文本或html脚本不会被执行
通常,php只解析扩展名被定义为.php的文件。而require函数则不同。
3 调用未定义的函数
检查:
函数名称的拼写是否正确
函数是否存在于所用的php版本库中
4 函数名称的大小写
函数调用不区分大小写
变量名称区分大小写
5 封闭php标记

<?php     function my_fun() {?>//这里必须有php封闭标记my function was called.<?php     }?>
Copy after login

6 内置函数
内置函数在所有的php脚本中都可以使用但如果声明自己的函数,它们只能在自己的脚本中使用。
php不支持函数重载,不能和内置函数重名。
避免再多个脚本中定义相同的函数名。
7 可变函数
name()并不是一个函数合法名称,但是一个它也可以正确执行,这是根据 name的值来确定。php取出保存在$name中的值,寻找具有那个名称的函数,并且调用该函数。这种函数被称为可变函数。
8 echo对变量的影响

function fn() {    $var = "contents";}fn();echo $var; // 什么也没有输出// 如下所示的例子刚好相反。在函数外部声明一个变量,然后在函数内部使用它<?phpfunction fn() {    echo "inside the function, \$var = ".$var. "<br/>"; // 创建一个局部变量 $var    $var = "contents 2"; // 改变局部变量 $var 的值    echo "inside the function, \$var = ".$var. "<br/>";}$var = "contents 1";fn();echo "outside the function, \$var = ".$var. "<br/>"// outputinside the function, $var = inside the function, $var = contents 2 outside the function, $var = contents 1 // 全局 $var 没有改变
Copy after login

9 global关键字
global可以用来手动指定一个在函数中定义或使用的变量具有全局作用域。

function fn() {    global $var;    $var = "contents";    echo "inside the function, \$var = ". $var ."<br/>";}fn(); echo "outside the function, \$var = ". $var ."<br/>";// outputinside the function, $var = contentsoutside the function, $var = contents
Copy after login

变量的作用域是从执行global $var这一句开始的。
当一个变量要在整个脚本中都要用到,在脚本的开始处使用关键字global

10 参数引用传递

function increment(&$value, $amount =1) {$value=$value+$amount;}$value = 1;echo $value; // print 1increment($value);echo $value; // print 2
Copy after login
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 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)

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

See all articles