4picht/upgradephp

http://include-once.org/p/upgradephp/ 的镜像

19.1.1 2016-07-05 09:37 UTC

This package is not auto-updated.

Last update: 2024-09-18 19:12:46 UTC


README

这是 UpgradePHP 项目的 Git 克隆版本。它是一个用于 PHP 4.1 到 PHP 5.1 安装环境的 PHP 5.3/5.4 函数的 shim/polyfill。由于我主要通过 Git 进行工作,而不是 fossil DVCS,所以我希望它在 Git 上。以下信息是从官方来源复制的。它可以适应从 composer 自动加载。但可能更好的方法是选择你想要的 polyfills。

说明

有了 'upgrade.php',你可以使用较新版本 PHP(目前为 5.3/5.4)的许多功能,而不会失去与旧解释器和过时的 web 服务器设置的兼容性。它会处理在运行时缺失的任何函数(使用它们的原始名称)的模拟。

你只需将其包含到应用程序中。然后你就可以从微管理向后兼容性和浪费时间在解决方案中解脱出来。只需使用功能更强大的 PHP 函数。

目前模拟的函数包括:gzdecode、hex2bin、class_uses、zlib_encode、zlib_decode、session_status、http_response_code、http_redirect、http_send_content_type、json_encode、json_decode、preg_filter、lcfirst、array_replace、strptime、error_get_last、preg_last_error、lchown、lchgrp、ob_get_headers、xmlentities、stripos、strripos、str_ireplace、get_headers、headers_list、fprintf、vfprintf、str_split、http_build_query、convert_uuencode、convert_uudecode、scandir、idate、time_nanosleep、strpbrk、php_real_logo_guid、php_egg_logo_guid、php_strip_whitespace、php_check_syntax、get_declared_interfaces、array_combine、array_walk_recursive、substr_compare、spl_classes、class_parents、session_commit、dns_check_record、dns_get_mx、setrawcookie、file_put_contents、file_get_contents、fnmatch、glob、array_key_exists、array_intersect_assoc、array_diff_assoc、html_entity_decode、str_word_count、str_shuffle、get_include_path、set_include_path、restore_include_path、str_rot13、array_change_key_case、array_fill、array_chunk、md5_file、is_a、fmod、floatval、is_infinite、is_nan、is_finite、var_export、strcoll、diskfreespace、disktotalspace、vprintf、vsprintf、import_request_variables、hypot、log1p、expm1、sinh、cosh、tanh、asinh、acosh、atanh、array_udiff_uassoc、array_udiff_assoc、array_diff_uassoc、array_udiff、array_uintersect_uassoc、array_uintersect_assoc、array_uintersect、array_intersect_uassoc、mime_content_type、image_type_to_mime_type、image_type_to_extension、exif_imagetype、array_filter、array_map、is_callable、array_search、array_reduce、is_scalar、localeconv、call_user_func_array、call_user_method_array、array_sum、constant、is_null、pathinfo、escapeshellarg、is_uploaded_file、move_uploaded_file、strncasecmp、wordwrap、php_uname、php_sapi_name

当然,只有当当前的 PHP 解释器本身不提供这些函数时,才会使用模拟的函数。

因此,在当前设置中,通常会调用本地函数。但你的应用程序将保证在任何人(无论 PHP 版本如何)处工作而不改变。仅保留 "PHP 4.1" 的最小兼容性要求。

还有一些类也被模拟。但将 SPL 或其他扩展迁移过来是一项工作量很大的任务。至今没有收到任何贡献。至于为什么 PHP.net 开发者从未想过为任何内容提供一个参考实现,这一点有些不清楚。

升级.php 包还提供了多个模拟包含脚本,用于更大的 PHP 扩展,如 gettext、ftp 和 ctype、mime 函数、odbc、dba。请参阅 Fossil 存储库中的 Wiki。

当然,模拟模块并不完全像原始的 C 实现 100% 一致,但 upgrade.php 扩展工作得比常见的解决方案代码片段要好得多,对于大多数应用程序来说应该是“足够好”的。

用法

if (PHP_VERSION < 5.1) { include_once("upgrade.php"); }
json_encode("this will always work now");

Ext 中的模块

gettext.php 添加了 _() 和各种 gettext() 功能。此扩展通常用于本地化应用程序。与其他方法不同,这种方法在源代码中应用起来非常简单。

ftp.php 使用纯 PHP 套接字函数重新实现了 FTP 访问。

ctype.php 提供了一套字符分类函数。

mime.php 有 MIME 魔法文件类型检测函数。

pdo.php 是 PHP 4.x 和 PHP 5.0 的 PDO 数据库抽象层的模拟。

pspell.php 使用命令行 aspell 工具来模拟 pspell_*() 类型的函数,用于检查自然语言拼写错误。

bcmath.php 用于任意精度数学函数。

php40array.php 存档了较少使用的数组函数。这已经从主脚本中提取出来,以保持其精简。

历史性的 php40.php 提供了一些用于 PHP 4.0 兼容性的函数。尽管如此,可能没有人还在运行这样旧的 PHP 版本。

非标准

与 upgrade.php 一起分发了一些函数集合,这些函数并不是真正的标准 PHP。作者只是太懒,不愿意创建单独的项目托管站点。

http_query.class.php 提供了 HttpRequest 功能。它部分兼容 PEAR::HTTPRequest,但主要是为了将来模拟 PHP/PECL http 扩展和 http_* 函数。

input.php 是一个高度推荐的安全特性。它将 $_GET、$_POST、$_REQUEST、$_COOKIE、$_SERVER 输入数组包装在一个面向对象的访问层中。这个面向对象的访问包装器仅通过过滤器特性允许访问提交的表单数据和 HTTP 变量。本质上,这强制执行输入验证,因为阻止了原始访问(或者至少可以记录下来)。

许可证

除非另有说明,所有脚本均为公共领域。

例如,PDO 扩展不是。