插件窝 干货文章 php7弃用的函数有哪些

php7弃用的函数有哪些

函数 替代 方案 PHP 464    来源:    2025-03-16

在PHP 7中,一些旧的函数和特性被弃用或移除,以推动更现代的编程实践和提高安全性。以下是一些在PHP 7中被弃用的主要函数和特性:

1. mysql_* 函数

  • 这些函数在PHP 5.5.0中被弃用,并在PHP 7.0.0中被移除。
  • 替代方案:使用 mysqli_*PDO 扩展。

2. ereg_* 函数

  • 这些函数在PHP 5.3.0中被弃用,并在PHP 7.0.0中被移除。
  • 替代方案:使用 preg_* 函数(PCRE 正则表达式)。

3. split() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.0.0中被移除。
  • 替代方案:使用 explode()preg_split()

4. call_user_method()call_user_method_array()

  • 这些函数在PHP 5.3.0中被弃用,并在PHP 7.0.0中被移除。
  • 替代方案:使用 call_user_func()call_user_func_array()

5. mcrypt_* 函数

  • 这些函数在PHP 7.1.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 openssl_* 函数或其他现代加密库。

6. create_function()

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用匿名函数(闭包)。

7. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

8. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

9. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

10. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

11. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

12. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

13. create_function()

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用匿名函数(闭包)。

14. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

15. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

16. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

17. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

18. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

19. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

20. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

21. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

22. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

23. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

24. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

25. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

26. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

27. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

28. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

29. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

30. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

31. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

32. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

33. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

34. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

35. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

36. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

37. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

38. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

39. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

40. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

41. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

42. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

43. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

44. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

45. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

46. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

47. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

48. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

49. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

50. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

51. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

52. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

53. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

54. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

55. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

56. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

57. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

58. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

59. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

60. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

61. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

62. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

63. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

64. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

65. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

66. assert() 作为字符串

  • 在PHP 7.2.0中,将字符串传递给 assert() 的行为被弃用。
  • 替代方案:传递布尔表达式或闭包。

67. track_errors 配置选项

  • 这个配置选项在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 error_get_last() 函数。

68. each() 函数

  • 这个函数在PHP 7.2.0中被弃用,并在PHP 8.0.0中被移除。
  • 替代方案:使用 foreach 循环。

69. __autoload() 函数

  • 这个函数在PHP 5.3.0中被弃用,并在PHP 7.2.0中被移除。
  • 替代方案:使用 spl_autoload_register()

70. unset() 用于 $this

  • 在PHP 7.2.0中,尝试在对象方法中使用 unset($this) 会引发警告。
  • 替代方案:避免在对象方法中取消 $this 的引用。

71. parse_str() 不带第二个参数

  • 在PHP 7.2.0中,parse_str() 不带第二个参数的行为被弃用。
  • 替代方案:始终使用第二个参数来存储解析结果。

72. **assert()