php获取硬盘可用
Yesterday, the PHP development team finally announced the moment many of us have been waiting for – the first stable release of PHP 7 – and there are many interesting new features and changes.
昨天,PHP开发团队终于宣布了我们许多人一直在等待的时刻-PHP 7的第一个稳定版本-并且有许多有趣的新功能和更改。
PHP 6在哪里? (Where’s PHP 6?)
At the time PHP 6 was under development, one of the major new features underway was to bring native Unicode support to PHP. This project alone caused significant delays in the overall progress of PHP 6 due to technical challenges. It was later decided to postpone the native Unicode project and merge the other new features that were originally intended for PHP 6 into a new version of the PHP 5.x branch.
在开发PHP 6时,正在进行的主要新功能之一就是为PHP带来本机Unicode支持。 由于技术挑战,仅此项目就导致PHP 6总体进度的重大延误。 后来决定推迟本机Unicode项目,并将原本打算用于PHP 6的其他新功能合并到PHP 5.x分支的新版本中。
Here is where the problem lies: many books on PHP 6 were published at the time it was under development. An unfortunate mistake for publishers to make, because features can and do change before feature-freeze.
这就是问题所在:在开发PHP 6时,已经出版了许多有关PHP 6的书。 对于发布者来说,这是一个不幸的错误,因为功能可以而且确实会在功能冻结之前发生更改。
So for a number of reasons, the PHP development team decided to skip PHP 6 entirely and start again with PHP 7.
因此,出于多种原因,PHP开发团队决定完全跳过PHP 6,然后重新开始使用PHP 7。
PHP 7有什么新功能? (What’s new in PHP 7?)
We’ll be covering the new features that the developers amongst you will be interested to learn about. You can find a simple summary of the changes in PHP 7 and how you can upgrade in the Migrating from PHP 5.6.x to PHP 7.0.x manual on the PHP website.
我们将介绍您中的开发人员有兴趣了解的新功能。 您可以在PHP网站上的《 从PHP 5.6.x迁移到PHP 7.0.x》手册中找到有关PHP 7更改以及如何升级的简单摘要。
我现在应该升级吗? (Should I upgrade now?)
Before we answer this question, it is worth mentioning PHP 7 was originally scheduled for release on November 12 but was postponed by two weeks due to some last-minute bugs that the PHP development team wanted to fix beforehand (and then postponed again on November 26). This should serve as a testament to the kind of quality to expect.
在我们回答这个问题之前,值得一提的是,PHP 7原定于11月12日发布,但由于PHP开发团队想预先修复的一些最新错误而推迟了两周(然后于11月26日再次推迟) )。 这可以证明所期望的质量。
For test environments, you should definitely upgrade as soon as possible so you can start testing your web applications against it. There are indeed changes in PHP 7 that may cause compatibility issues with a small subset of web applications – so don’t blindly upgrade to PHP 7 on a production environment until you are at least confident your web application works flawlessly under PHP 7, as it is a substantial upgrade from PHP 5.6 with many new features and changes.
对于测试环境,您绝对应该尽快升级,以便可以针对它测试Web应用程序。 实际上,PHP 7中的更改可能会导致与一小部分Web应用程序的兼容性问题–因此,在您至少确信Web应用程序在PHP 7下可以完美运行之前,请勿在生产环境中盲目升级到PHP 7。是PHP 5.6的重大升级,具有许多新功能和更改。
Now the inevitable question: should I upgrade my production environment? While PHP 7 is now “stable”, it might be a bit premature to upgrade just yet because there might be unknown bugs or vulnerabilities that are only spotted now that PHP 7 is in the wild.
现在不可避免的问题是:我应该升级生产环境吗? 虽然PHP 7现在“稳定”了 ,但升级可能还为时过早,因为可能由于PHP 7泛滥才发现未知的错误或漏洞。
It might be wiser to wait at least a couple months and in the meantime trying out the new version on a test environment to verify its compatibility with your web applications – deciding from there.
至少等待几个月,然后在测试环境中尝试新版本以验证其与Web应用程序的兼容性,这是明智的选择。
在GNU / Linux发行版上升级到PHP 7 (Upgrading to PHP 7 on GNU/Linux distributions)
For some distributions that favour stability over new features, you might not be able to upgrade to PHP 7 until the distribution maintainers bring out a new stable release. For Debian in particular, this might not be until 2017 – the usual period between stable releases appear to be roughly every two years. And from what we’ve heard, PHP 7 won’t be made available in Debian backports.
对于某些支持稳定性而不是新功能的发行版,您可能无法升级到PHP 7,直到发行版维护人员推出新的稳定版本为止。 特别是对于Debian,这可能要等到2017年–稳定版本之间的通常间隔时间大约是两年一次。 而且据我们所知,Debian反向端口中不会提供PHP 7。
Other distributions like Arch Linux and openSUSE should see PHP 7 hit the repositories in the near future.
其他发行版(例如Arch Linux和openSUSE)应该会在不久的将来看到PHP 7进入存储库。
In all cases of course, you can always compile and install PHP yourself if you are eager to try it now. This is certainly the route you’ll need to take if you are running Debian 8 or CentOS 7.
当然,在所有情况下,如果您现在都想尝试PHP ,则可以随时自己编译并安装PHP 。 如果您正在运行Debian 8或CentOS 7,这当然是您需要采取的方法。
因此,让我们进入令人兴奋的部分……PHP 7的新功能是什么? (So let’s get to the exciting parts… what’s new in PHP 7?)
PHP 7:比PHP 5.x快2倍 (PHP 7: 2x faster than PHP 5.x)
Thanks to a group of Zend developers working on PHPNG – a development branch of PHP that was originally created to experiment with a JIT (Just In Time) engine – PHP 7 benefits from up to 2x faster performance over PHP 5.x.
感谢一群Zend开发人员致力于PHPNG (PHP的一个开发分支,最初是为了测试JIT(及时)引擎)而开发的,PHP 7的性能比PHP 5.x快2倍。
This branch, later merged into PHP 7, features significant performance improvements in memory management. No, PHP has not become a JIT engine. If you’re interested in that, take a look at HHVM.
该分支后来合并到PHP 7中,在内存管理方面具有显着的性能改进。 不,PHP尚未成为JIT引擎 。 如果您对此感兴趣, 请查看HHVM 。
Speaking of which, the good folks at Phoronix.com did some benchmarking between PHP 7 and HHVM. To the surprise of many – and us too – PHP 7 was found to have better performance in all the tests conducted except memory footprint.
说到这,Phoronix.com的好伙伴在PHP 7和HHVM之间进行了一些基准测试 。 令许多人(我们也感到惊讶)的是,PHP 7在所有执行的测试中均具有更好的性能,但内存占用量除外。
PHP 7:返回类型声明 (PHP 7: Return Type Declarations)
One for the programmers: you can now define the expected return type of any function or method. If the returned type is not the same as the one declared, an E_ERROR is thrown. Defining a return type is simple:
程序员专用的一种:现在,您可以定义任何函数或方法的预期返回类型。 如果返回的类型与声明的类型不同,则引发E_ERROR 。 定义返回类型很简单:
function returnInt(): int
{
echo 42;
}
Now it might sound strange for an interpreted scripting language to introduce return type declarations, but imagine how beneficial this will be for object interfaces – it provides assurance that any implementing class will never return unexpected values – and likewise for classes that inherit abstract classes.
现在,对于解释型脚本语言引入返回类型声明来说可能听起来很奇怪,但可以想象一下这对于对象接口将有多大好处-它确保任何实现类永远不会返回意外值-以及继承抽象类的类也是如此。
PHP 7:不赞成使用PHP 4构造函数 (PHP 7: Deprecation of PHP 4 constructors)
Creating constructor methods in PHP 4 involved defining a normal method that used the same name as the class it resides in. It wasn’t until PHP 5 saw the introduction of the __construct() magical method to perform the same function.
在PHP 4中创建构造函数方法涉及到定义一个普通的方法,该方法使用与其所在类相同的名称。直到PHP 5看到引入__construct()神奇方法来执行相同的功能。
Of course, PHP 4 style constructor methods are supported in PHP 5.x for backwards compatibility, but will raise an E_DEPRECATED notice in PHP 7.
当然,PHP 5.x支持PHP 4样式构造函数方法以实现向后兼容,但是在PHP 7中会引发E_DEPRECATED通知。
You can hide these notices in your php.ini configuration file, but this shouldn’t be relied upon because PHP 4 constructor methods are scheduled for complete removal in PHP 8. From this point on, these methods will act like any other normal method and will not be immediately executed when the class is initialised.
您可以将这些通知隐藏在php.ini配置文件中,但是不应依赖于此,因为已计划将PHP 4构造函数方法在PHP 8中完全删除。从这一点开始,这些方法将像其他任何普通方法一样工作,并且初始化该类时不会立即执行。
PHP 7:删除替代PHP标签 (PHP 7: Removal of alternative PHP tags)
To little surprise, the PHP development team have removed support for ASP- and HTML-style PHP tags, which includes:
毫不奇怪,PHP开发团队删除了对ASP和HTML样式PHP标签的支持,其中包括:
<% opening tag
<%= opening tag with echo
%> closing tag
If your scripts rely on these alternative PHP tags, you’ll need to replace these with the standard PHP opening/closing tags, which are:
如果您的脚本依赖于这些替代PHP标签,则需要用标准PHP打开/关闭标签替换它们,它们是:
<?php opening tag
<? short opening tag (requires short_open_tag enabled)
<?= opening tag with echo
?> closing tag
PHP 7:匿名类 (PHP 7: Anonymous Classes)
In PHP 5.x, we can create anonymous functions (also called closures) like this:
在PHP 5.x中,我们可以创建匿名函数(也称为闭包 ),如下所示:
$var = function() { … }
echo function() { … }
A closure is simply a normal function that hasn’t a name defined. It’s useful for executing logic that returns a value at the end, but has other practical uses too.
闭包只是一个普通的函数,没有定义名称。 这对于执行最终返回一个值的逻辑很有用,但也具有其他实际用途。
New in PHP 7 is the ability to create anonymous classes in the same way you can create anonymous functions. It’s just as easy – here’s a brief example:
PHP 7中的一项新功能是能够以与创建匿名函数相同的方式创建匿名类。 一样简单–这是一个简单的示例:
$class = new class {
public function getDate() {
return date('F j, Y g:i a');
}
};
PHP 7:组合比较运算符 (PHP 7: Combined Comparison Operator)
Dubbed the “spaceship operator,” this returns either 1, 0 or -1 depending on whether both operands are equal to, or if one is greater than or less than the other. That might sound like a handful – but it’s really rather simple. Here’s an example:
被称为“太空飞船运营商”,它会根据两个操作数是否相等,或者一个大于或小于另一个来返回1、0或-1。 听起来可能很少,但是确实很简单。 这是一个例子:
if(1 <==> 1) // 0
if(1 <==> 0) // 1
if(0 <==> 1) // -1
This becomes useful in a number of scenarios e.g. for sorting arrays with usort().
这在许多情况下变得很有用,例如,使用usort ()对数组进行排序。
PHP 7:空合并运算符 (PHP 7: Null Coalescing Operator)
This is a really handy new ternary operator – it allows us to return the first operand if it exists or is not NULL, or else its second operand.
这是一个非常方便的新三元运算符–它允许我们返回第一个操作数(如果存在或不为NULL) ,或者返回第二个操作数。
This might sound very similar to the short ternary ?: operator – and it is – but the problem with that is an E_NOTICE error will be raised if the value being checked does not exist; Here’s how the new null coalescing operator works:
这听起来与短三元?:运算符非常相似,但确实如此,但是如果不存在所检查的值,则将引发E_NOTICE错误; 这是新的空合并运算符的工作方式:
$username = $users->username ?? 'Guest';
是什么让PHP 7无法实现? (What didn’t make it to PHP 7?)
There were many features and changes that were tabled for inclusion in PHP 7 that were either rejected or stalled either due to the author withdrawing or lack of consensus.
由于作者撤回或缺乏共识,PHP 7中包含许多功能和更改,这些功能和更改被拒绝或停滞。
One of the big changes that I was hoping to see approved for PHP 7 was the addressing of inconsistent PHP function names – and this was added as an RFC in March 2015, but has not moved from discussion stage since it was created.
我希望看到被批准用于PHP 7的重大更改之一是解决了不一致PHP函数名称的问题–该功能于2015年3月作为RFC添加,但自创建以来一直没有脱离讨论阶段。
I contacted the author of this RFC to ask about the progress and from what the author has told me, it looks like we might see movement in this RFC starting early next year.
我联系了该RFC的作者,询问进展情况以及作者告诉我的内容,看来我们可能会在明年初开始看到该RFC的发展。
So what does this RFC intend to address? The main purpose of the RFC is to create alias functions that are more consistently worded. For example all GD functions use cryptic function names like imagecreatetruecolor() and imagecreatefromgd2part(), and some are less cryptic but clearly inconsistent, like image_type_to_extension() and image_type_to_mime_type().
那么,这个RFC打算解决什么呢? RFC的主要目的是创建别名功能,使其措词更加一致。 例如,所有GD函数都使用诸如imagecreatetruecolor()和imagecreatefromgd2part()之类的隐秘函数名,而一些隐秘性较低但明显不一致的函数 ,例如image_type_to_extension()和image_type_to_mime_type() 。
In the case of the functions above, the RFC proposes to create more consistently-worded alias functions like gd_create_true_color(), gd_create_from_gd2_part(), gd_type_to_extension() and gd_type_to_mime_type(). It’s also good to point out the changes this RFC is proposing are completely backwards-compatible, because they will simply be aliases and not sudden drop-in replacements.
对于上述功能,RFC建议创建措辞更一致的别名函数,例如gd_create_true_color() , gd_create_from_gd2_part() , gd_type_to_extension()和gd_type_to_mime_type() 。 指出此RFC提出的更改是完全向后兼容的,这也很好,因为它们只是别名,而不是突然的替换。
翻译自: https://www.eukhost.com/blog/webhosting/php-7-is-now-available-find-out-whats-new/
php获取硬盘可用