通过比较的方式总结php基础知识点,这篇文章在以后的开发中不断完善,文章中难免有理解和书写错误,欢迎指正!
echo、print、print_r、var_dump、var_export的区别echo 语言结构非函数 可以用逗号分隔打印多个值 无返回值 可以打印整形、字符串;打印布尔型(ture是1,false是空) print 语言结构非函数 只能打印一个值 有返回值 可以打印整形、字符串;打印布尔型(ture是1,false是空) print_r 函数 可以打印整形、字符串、数组、对象;打印布尔型(true是1,false和null是空) 第二值为true可以赋值给php变量 var_dump 函数 可以用逗号分隔打印多个值 可以打印所有类型的值 var_export 函数 与var_dump类似,第二个值为ture返回值可以赋值给php变量
require、include、require_once、include_once的区别require 出错时产生 E_COMPILE_ERROR 级别的错误,导致脚本中止 include 出错时产生 E_WARNING 警告,脚本继续运行 require_once和include_once 只引入文件一次;
php包含文件的寻找路径按给出的参数路径寻找 –> 没有给出目录按照include_path制定目录寻找 –> include_path没有文件,则在脚本文件所在目录和当前工作目录寻找
php数组合并 + 和array_merge区别array_merge 字符串键名:后面的值覆盖前面的值;数字键名:后面的不会覆盖前面的,附加到后面;如果只有数字键名,会重建索引; +字符串键名和数字键名都用前面的,后面的忽略;
php new self() 和 new static()的区别new static()是在PHP5.3版本中引入的新特性;new self()和new static()都是实列对象; 没有被继承两者无区别返回类对象;类被继承new self返回父类对象,new static返回子类对象;
<?php class A { public static function get_self() { return new self(); } public static function get_static() { return new static(); } } class B extends A {} echo get_class(B::get_self()); // A echo get_class(B::get_static()); // B echo get_class(A::get_self()); // A echo get_class(A::get_static()); // A final关键词PHP 5 新增了一个 final 关键字。如果父类中的方法被声明为 final,则子类无法覆盖该方法。如果一个类被声明为 final,则不能被继承
接口和抽象类的区别魔术方法
__construct()、__destruct()、__call()、__get()、__set()、__isset()、__unset()、__sleep()、__wakeup()、__toSting()、__invoke()、__clone()
9.php自动加载__autoload和spl_autoload_register自动加载函数区别
spl_autoload_register可以多次注册加载,按顺序谁先注册谁先加载;__aotuload只能定义一次 spl_autoload_register可以被catch到错误,而__aotuload不能 spl_autoload_register注册的加载函数可以被spl_autoload_unregister掉