HOME  → POSTS  → 2011

Awesome new features coming in PHP 5.4

Projects and Code156 words1 minutes to read

The next version of PHP, which saw its first release candidate today, has some really awesome new features. You can see a complete list of changes in the README, but here are the ones that caught my eye.

Classes

  • Support for Traits (i.e., mix-ins; addresses the multiple-inheritance problem).
  • Support for chaining from the constructor: (new Class)->method()
  • Support for Class::{expr}() syntax.
  • Closures inherit $this from the outer scope.
  • Added ReflectionClass::newInstanceWithoutConstructor() to create a new instance of a class without invoking its constructor.
  • Added a new typehint: callable

Improvements

  • Array dereferencing and short array syntax: echo [1, 2, 3][0]
  • json_encode() now supports these additional flags: JSON_UNESCAPED_UNICODE, JSON_BIGINT_AS_STRING, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT and JSON_UNESCAPED_SLASHES.
  • Multibyte support is enabled by default.
  • Faster unserialize() and ternary operator performance.
  • IPv6 support.

Fixing the cruft

  • ext/mysql, mysqli and pdo_mysql now use mysqlnd by default.
  • Removed magic quotes, safe mode, register globals, allow call-time pass-by-reference, and more!
  • Default character set is now UTF-8 instead of ISO-8859-1.

is an engineering manager with over 20 years of experience across software development, site reliability engineering, and security. He is the creator of SimplePie and AWS SDK for PHP, patented multifactor-authentication-as-a-service at WePay, defined much of the CI/CD and SRE disciplines at McGraw-Hill Education, and came up with the idea of “serverless, event-driven, responsive functions in the cloud” while at Amazon Web Services in 2010. Ryan's aptly-named blog, , is where he writes about ideas longer than . Ambivert. Curious. Not a coffee drinker.