Thiemo Mättig

Thiemo’s Weblog

We, the Wikidata team and MediaWiki in general, are looking forward to upgrade our minimum system requirement from PHP 5.3 to PHP 5.5. This was and is discussed for quite some time now, and will probably take some more time. But it feels we are getting closer, and I realized I have no idea what the step from 5.3 to 5.5 actually means. Just recently I learned there is yield, today I learned there is a ::class syntax, but what do they do? Time to look at what's new in PHP 5.5.

PHP 5.4:

  • traits.
  • Short array syntax with [] square brackets instead of array().
  • Closures finally support $this.
  • ( new Class() )->method().
  • function()[0].
  • Binary numbers, e.g. 0b1000, just like in Java 7.
  • register_globals and magic quotes are removed. Wow. This is incredible. A good thing, but still incredible when you realized these two features are the main reason PHP was created in the first place.

PHP 5.5:

  • SELF is recognized in uppercase. I wonder why. They use SELF::CONSTANT as an example, but what's wrong with self::CONSTANT?
  • These extremely weird logo GUIDs are finally killed, including php_logo_guid() and such.
  • Generators. Use a function in a foreach loop, use yield in the function to return the elements for the loop. Magic.
  • try-catch also supports finally. Wow, finally.
  • One can use foreach ( $twoDimensionalArray as list ( $a, $b ) ).
  • You can use functions in empty.
  • "string"[0] and [1, 2, 3][0], obviously not very useful in production, but really nice when debugging and testing. Do not confuse this with $string[0], which is supported since basically forever.
  • ::class returns the full qualified class name. Extremely useful in PHPUnit's getMock and setExpectedExpression.
  • imageflip. Haha.

Kommentare zu diesem Beitrag können per E-Mail an den Autor gesandt werden.

[ < Zurück zur Übersicht ]

Impressum & Datenschutz