PHP 5.5.0 Alpha 6 - Released
php.net
php.net
Large language changes:
* Generators and coroutines (https://wiki.php.net/rfc/generators by me)
* `finally` blocks (https://wiki.php.net/rfc/finally by laruence)
Syntactic sugar:
* Support for function calls in `empty()` (https://wiki.php.net/rfc/empty_isset_exprs by me)
* Support for `list()` in foreach (https://wiki.php.net/rfc/foreachlist by laruence)
* Constant array/string dereferencing (https://wiki.php.net/rfc/constdereference by laruence)
* Getting the fully qualified class name using `ClassName::class` (https://wiki.php.net/rfc/class_name_scalars by ralph)
Standard library:
* Simplified password hashing API (https://wiki.php.net/rfc/password_hash by ircmaxell)
* `hash_pbkdf2()` function (https://wiki.php.net/rfc/hash_pbkdf2 by ircmaxell)
* DateTimeImmutable, which is an immutable variant of DateTime (by derick)
Key anti-features (aka BC breaks):
* Dropped Windows XP and 2003 support (by pierre)
* ext/mysql deprecated (https://wiki.php.net/rfc/mysql_deprecation by aharvey)
* preg_replace /e modifier deprecated (https://wiki.php.net/rfc/remove_preg_replace_eval_modifier by me)
* Logo GUIDs removed (by ajf)
For the beta 1 (the next planned released) at least two more things are planned:
* Bundling of ZendOptimizer+ (https://wiki.php.net/rfc/optimizerplus by zeev)
* Allowing non-scalar Iterator keys in foreach (https://wiki.php.net/rfc/foreach-non-scalar-keys by me)
Any news on object literals $o = {'abc': 456}; and scalar type hint ?
Thanks for all the hard work, improvement in the language in 5.3 and 5.4 were awesome.
Object literals and scalar type hints won't be in 5.5. Scalar type hints may be in the next version (it's a rather tricky topic). For object literals I don't see reason to add them at all (in PHP you can just use arrays ^^).
Which thankfully aren't as painful now!
$cfg = [
'path' => '.',
'mask' => 655
];
Otherwise, if we still had to write "array" each time, I'd be more supportive of the object-literal, although I do think there's value in the literal but mostly to make the language similar to other languages with similar constructs (js, py). $o = (object)[
'foo' => 'bar'
];
Personally I think there should be a way to create objects right away instead of having to cast an array. Maybe there is a good reason all together for not using objects but I very much prefer typing $var->field instead of $var['field']. $o = (object)[
'foo' => function(){ print 'bar'; },
];
$o->foo();
You have to do it this way: call_user_func($o->foo);
Or this way: $foo = $o->foo;
$foo();
Which doesn't work when foo is defined as a class method.Using __get/__set behaves the same way. Let's say $o is of SomeType that defines those magic methods. You can have a function foo on that type that is defined as a public method.
$o->foo(); // the actual instance method
$o->foo = function() { print 'bar'; };
$o->foo(); // same instance method
$foo = $o->foo;
$foo(); // prints bar
In the case of StdClass it might be possible to do it your way where foo could be callable ($o->foo()) but I can see why they wouldn't allow this in order to keep things consistent.Edit: It also behaves the same way if you assign a function to a public field of a class (I'm using 5.4) so I actually support not allowing a method to be directly callable in this fashion because this would be the only case where this behavior would occur.
$data = {
firstName: "John",
lastName: "Smith",
age: 25,
address: {
streetAddress: "21 2nd Street",
city: "New York",
state: "NY",
postalCode: 10021
},
phoneNumber: {
home: {
number: "212 555-1234"
},
fax: {
number: "646 555-4567"
}
}
};
Rather than the awkward and verbose: $data = (object) [
"firstName" => "John",
"lastName" => "Smith",
"age" => 25,
"address" => (object) [
"streetAddress" => "21 2nd Street",
"city" => "New York",
"state" => "NY",
"postalCode" => 10021
],
"phoneNumber": (object) [
"home" => (object) [
"number" => "212 555-1234"
],
"fax" => (object) [
"number" => "646 555-4567"
]
]
];
JSON is everywhere these days, supporting object literals is a very, very big deal; I understand which features to implement are handpicked very carefully so as not to clutter more the core, but we are talking about making the life of devs who use and write JSON more difficult, and that happens to be lots of folks.Telling people to use arrays and be done with it is the equivalent of implement a strpos function that may only accept a string that's 5 characters long — yes, theoretically you can work with that splitting your strings, but that's time consuming and a inconsistent behaviour (why would 10 character long strings be less of a citizen than 5 char long ones?)
Since I've moved to the camp of "You developing PHP and use Windows? Let me show you how to setup Vagrant" I've become less concerned about the state of PHP & Windows. I just won't tolerate when people say PHP dropping XP support is a good thing (which the OP wasn't saying, but some have.)
If your company is affected by lack of XP support in this PHP build, it should be a temporary convenience at worst. What are your plans to migrate off XP over the next year? As of next April there will be no patches or security fixes coming for XP. Is your company planning on paying Microsoft for continued support, or will it negotiate extended XP support in return for buying company-wide Windows 8 licenses and start the ride over again?
I suspect that many of the people using XP today are frozen and wouldn't upgrade their PHP anyway, for the same reasons they're using XP and IE6. They either don't want to change their software because of cost/risk issues or the people who wrote it moved on years ago and they have no idea how it works.
There's not been any security patches for PHP 4 for many years, but people still use it. Those same sorts of orgs will continue to use stuff out of date and unsupported for any number of reasons. Catering development processes around an increasingly small number of users doesn't make sense.
1. http://lxr.php.net/search?q=&defs=&refs=NETWARE&...
For example, I have two Rails apps that are running on Rails 2.2.x, so yeah, they're way behind, and I feel some sense of urgency to upgrade them soon... but I believe I am an outlier in the Ruby/Rails community in the sense that I am not upgrading all the time.
About a month or two before I decide to upgrade I run the newer version locally while I'm developing (but being sure to not use any newer features). This usually weeds out any major incompatibilities and fix new warnings.
That said, I'm running 5.3 in production and have no real plans to upgrade to 5.4 anytime soon.
May I ask: why not?
If you want to see the patches go into the Debian/Ubuntu packages, run apt-get source php5 and look at the php5-$version/debian/patches directory. The build process uses a quilt wrapper (dh_quilt_patch) to apply them in the correct order. There are patches for building (in general or for a specific architecture), segmentation faults, security issues, manual pages and very few configuration changes (mostly just FHS compliance).
Fedora users have it easy, the packages there are mere days behind: https://admin.fedoraproject.org/updates/php
With a bit of experimenting you can easily do a network install of a headless Fedora/SL/CentOS in KVM using virt-install and a kickstart file. Use filesystem passthrough to access your source files, run php-fpm and configure its address as a backend in your web server. Keep SELinux enabled, but adjust it to your needs using setsebool if necessary.
I've tried Fedora in the past. I found it unstable and broken and I don't like RPM very much. It's undoubtedly improved since I last tried it (c. 2005-2006) but I don't miss RPM at all.
The thing about PHP is that since it's massively used around the net, rather than forcing devs to catch up with the language, PHP devs themselves try as much as possible not to break backwards compability. Which in many ways is a pity, but that seems to be the direction of the language at the moment.
A large number of web hosts still run PHP 5.2.x, while many have migrated to PHP 5.3. My last PHP 5.2-based client moved to a PHP 5.3-enabled web host a few weeks ago, so I'm finally free to use namespaces and closures.
Debian Stable and Ubuntu LTS are currently on PHP 5.3.x, which I suspect is partially responsible for the lack of PHP 5.4 adoption.
As for myself, I'm planning to rebuild my Ubuntu LTS dev box when Mint 15 comes out, so that's when I'll be upgrading to PHP 5.4. No need to hurry when none of my clients can use it anyway.
I wish all hosting providers would make newer versions available, then maybe open source projects would move with the times, and start bringing everyone up to date.
However there's a lot of arguing on php.internals about whether or not the right number of votes was reached (based on a not-specific-enough RFC on voting) so it may not even make it in.
[0]: http://files.zend.com/help/Zend-Server-Community-Edition/con...
ZO+ was chosen over APC because it is more stable. ZO+ is (more or less) PHP 5.5 compatible already, whereas APC still tries to cope with 5.4 compatibility.
https://gist.github.com/ck-on/4959032
I've found Optimizer+ has a few shortcomings, like no way to delete individual files from the cache, it's an all or nothing reset if you turn off file stat.
However it's definitely a bit faster than APC, at least 10% in most cases because of its multiple optimization passes.
I'm also looking forward to 3 things that AREN'T going to be there: register_global, safe mode, and magic_quotes
[1]http://www.php.net/manual/en/migration54.incompatible.php
PHP in particular seems to have a lot of bad home brew implementations out there, so it'll be nice to have a better default.
Personally I'm pretty happy with traits and array dereferencing against function returns. The new array literal syntax is nicer and more like other languages, in that you don't have to wrap everything with array(), instead just use the [] syntax.
Feature-wise 5.4 added traits and 5.5 has generators.