Web开发人员希望拥抱PHP 5.6创新功能

Ever since it came into existence, PHP has been serving web developers incredibly effective features and functions that have helped them in delivering high-end websites and web applications. After gathering immense appreciation for its 5.4 version, PHP has now come up with the 5.6 version that’s equipped with unexpectedly rich features that are surely going to help web developers take a sigh of relief. Through this post, I intend to throw some light on the lesser-known features of PHP 5.6 which look promising when it comes to building out-of-the-box web portals and apps.

自诞生以来,PHP就一直在为Web开发人员提供难以置信的有效功能,这些功能已帮助他们交付高端网站和Web应用程序。 在获得5.4版本的巨大赞赏之后,PHP现在推出了5.6版本,该版本配备了意想不到的丰富功能,这些功能肯定会帮助Web开发人员松一口气。 在这篇文章中,我打算介绍一些鲜为人知PHP 5.6功能,这些功能在构建现成的Web门户和应用程序时看起来很有希望。

对文件上传进行审核 (Moderations made to File Uploads)

Before the release of the PHP version 5.6, it wasn’t possible for the developers to upload stuff that occupied over 2GB memory space. Poor handling and processing were the two basic reasons behind this incompetency of PHP 5.6. Now, the PHP development team has outlines that the software now fully supports the file uploads of arbitrary size. Also, PHP 5.6’s data memory usage has been reduced by 2-3 times as compared to that of PHP 5.4. Such modifications to the file upload system has enables developers to re-open and re-use the input in accordance to their varying requirements.

在PHP 5.6版本发布之前,开发人员不可能上传占用2GB以上内存空间的内容。 处理和处理不当是PHP 5.6不能胜任工作的两个基本原因。 现在,PHP开发团队已经概述了该软件现在完全支持任意大小的文件上传。 另外,与5.4相比,PHP 5.6的数据内存使用量减少了2-3倍。 对文件上传系统的此类修改使开发人员能够根据他们的不同要求重新打开并重新使用输入。

导入命名空间常量和函数的灵活性 (Flexibility to import Namespace Constants and Functions)

Unlike the previous versions of PHP, the version 5.6 enables you to import the namespaced constants and functions directly into a suite of classes. Here’s the code snippet that’s used for importing the namespace constants and functions:

与以前PHP版本不同,版本5.6使您可以将命名空间常量和函数直接导入到一组类中。 这是用于导入名称空间常量和函数的代码片段:

namespace NamespaceTest {

const SCORE = 1;

function getScore() {

# ...

}

}

namespace {

use NamespaceTest as Test;

var_dump(TestgetScore());

}

If you’re keen on importing the standalone segments of code, then you can do the same in PHP 5.6 with the help of use function and use const statements as explained below:

如果您希望导入独立的代码段,则可以在PHP 5.6中借助use函数并使用const语句来执行相同的操作,如下所述:

namespace {

use function NamespaceTestgetScore;

use const NamespaceTestSCORE;

getScore();

}

更好地支持可变参数功能 (Better support for Variadic functions)

PHP Version 5.6 comes with full-fledged support for variadic functions. This makes it simpler for the developers to deal with variable argument lists available for methods and functions. Variadic functions play a vital role in improving readability and reducing the code complexity that’s prevalent during the process of handling variable argument lists. And that’s not all, PHP 5.6 also comes with some amazing improvements for the syntac used for these variadic functions. In other words, with PHP 5.6, even after supplying some arguments to the variadic functions, you don’t need to do any splicing after calling the function: func_get_args.

PHP 5.6版提供了对可变参数函数的全面支持。 这使开发人员可以更轻松地处理可用于方法和函数的变量参数列表。 可变参数函数在提高可读性和减少在处理变量参数列表的过程中普遍存在的代码复杂性方面起着至关重要的作用。 不仅如此,PHP 5.6还对这些可变参数函数使用的句法进行了一些惊人的改进。 换句话说,使用PHP 5.6,即使在为可变参数函数提供一些参数之后,您也无需在调用函数func_get_args之后进行任何拼接。

The syntax used for variadic functions in PHP 5.5 was as mentioned below:

PHP 5.5中可变参数函数使用的语法如下所述:

class MySQL implements DB {

protected $pdo;

public function query($query) {

$stmt = $this->pdo->prepare($query);

$stmt->execute(array_slice(func_get_args(), 1));

return $stmt;

}

// ...

}

$userData = $db->query('SELECT * FROM users WHERE id = ?', $userID)->fetch();

In contrast to above, the syntax used for variadic functions in PHP 5.6 is as explained below:

与上述相反,PHP 5.6中用于可变参数函数的语法如下:

class MySQL implements DB {

public function query($query, ...$params) {

$stmt = $this->pdo->prepare($query);

$stmt->execute($params);

return $stmt;

}

// ...

}

支持内部操作员重载 (Support for Internal Operator Overloading)

This is a feature, which I’m sure most of the PHP developers might not be aware of. PHP 5.6 comes with support for operator operating in internal classes, making the development process simpler and the code easier-to-read. Well, there are several reasons that made overloaded operators a better choice than the gmp_add($a, $b) style functions. Two of the most crucial ones are mentioned below:

这是一个功能,我敢肯定,大多数PHP开发人员可能都不知道。 PHP 5.6附带对在内部类中进行操作的操作的支持,从而使开发过程更简单,代码更易于阅读。 嗯,有很多原因使重载运算符比gmp_add($ a,$ b)样式函数更好。 以下是两个最关键的问题:

  • Code that uses the overloaded operators is simpler to read.

    使用重载运算符的代码更易于阅读。
  • Overloaded operators allow polymorphism for the functions that perform a variety of arithmetic operations.

    重载运算符允许执行各种算术运算的函数具有多态性。

大幅减少POST数据内存使用量 (A considerable reduction in the POST data memory usage)

As compared to the PHP 5.4, the version 5.6 comes with a POST data memory usage that’s been reduced by over 2-3 times. This has been made possible with the removal of two things:

与PHP 5.4相比,版本5.6的POST数据内存使用量减少了2-3倍以上。 去除了两件事,这已经成为可能:

  • The always_populate_raw_post_data setting from the php.ini file

    php.ini文件中的always_populate_raw_post_data设置
  • The superglobal variable $HTTP_RAW_POST_DATA

    超全局变量$ HTTP_RAW_POST_DATA

With the new PHP 5.6 release, you no longer need to access raw post data, rather you need to rely on a solution as mentioned below:

使用新PHP 5.6版本,您不再需要访问原始帖子数据,而是需要依赖于如下所述的解决方案:

$postdata = file_get_contents("php://input");

改进的ZIP库 (An improved ZIP library)

PHP 5.6 comes with an improved Zip library in the form of new methods. ZipArchive: : setPassword($password) is the methods that allows you to create password protected Zip files in a flexible way.

PHP 5.6附带了以新方法形式改进的Zip库。 ZipArchive::setPassword($ password)是使您可以灵活地创建受密码保护的Zip文件的方法。

摘要 (Summary)

PHP 5.6 definitely looks befitting for developers who are into the habit of exploring PHP and its components for building fine-quality apps and websites. Do share your feedback/comments on my write-up using the comments box below.

PHP 5.6绝对适合那些习惯于探索PHP及其组件以构建高质量应用程序和网站的开发人员。 请使用下面的评论框分享您对我的文章的反馈/评论。

Author Bio: Maria Mincey is a prolific writer, who brings to the table a quantum of knowledge around PHP Development Services and combines it with her creative writing skills. She works for Xicom Technologies Software Development Company.

作者简介 :Maria Mincey是一位多产的作家,他向人们介绍了有关PHP Development Services的知识,并将其与她的创造性写作技能相结合。 她在Xicom Technologies软件开发公司工作。

翻译自: https://www.journaldev.com/5236/php-5-6-innovative-features-web-developers-would-love-to-embrace

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值