Your SlideShare is downloading. ×
PHP 5.4: Die wichtigsten Neuerungen im Überblick
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

PHP 5.4: Die wichtigsten Neuerungen im Überblick

2,605
views

Published on

Die wichtigsten Neuerungen von PHP 5.4, insbesondere Traits, werden vorgestellt. …

Die wichtigsten Neuerungen von PHP 5.4, insbesondere Traits, werden vorgestellt.

Ein Videostream zu diesem Talk ist unter http://www.ustream.tv/recorded/21104071/highlight/251550 zu sehen.

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,605
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PHP 5.4Die wichtigsten Neuerungen im Überblick @ManuelKiessling
  • 2. SHORT ARRAY SYNTAX$a = array(‘a‘, ‘b‘, ‘c‘);$a = [‘a‘, ‘b‘, ‘c‘];$a = [one => 1, two => 2];
  • 3. FUNCTION ARRAY DEREFERENCING function foo() { return array(1, 2, 3); } echo foo()[2]; // prints 3
  • 4. CLASS MEMBER ACCESS ON INSTANTIATIONclass Foo { public function bar() { echo ‘foobar’; }}(new Foo)->bar(); // foobar
  • 5. TRAITS“The best way to understand what traits areand how to use them is to look at them for whatthey essentially are: language assisted copy andpaste.If you can copy and paste the code from oneclass to another then you have a candidate for atrait.”
  • 6. TRAITSUnterschiedlich Klassen implementieren unterschiedliches Verhalten – aber es gibt einige Aspekte, die in praktisch allen Klassen eines Systems implementiert werden sollen. User Item Verhalten: login() order() buy() ship() pay() changeColor() Aspekt: logging logging
  • 7. TRAITSclass User { public function login() { //... $this->logger->log(‘login’, $user->name, time()); }}class Item { public function ship() { //... $this->logger->log(‘shipped’, $item->id, time()); }}
  • 8. TRAITS Unterschiedlich Klassen implementieren unterschiedlichesVerhalten – aber es gibt einige Aspekte, die in praktisch allen Klassen eines Systems implementiert werden sollen. User Item Verhalten: login() order() buy() ship() pay() changeColor() Aspekt: logging logging
  • 9. TRAITS Was, wenn das logger Objekt ab sofort den Zeitstempel als ersten Parameter erwartet?Wie verhindern wir, dass wir in allen Klassen, die den Logger verwenden, den Code anpassen müssen?
  • 10. TRAITSVariante 1: Gemeinsame Vererbung log() LoggableObject User Item $this->log() $this->log()
  • 11. TRAITSclass LoggableObject { public function log(event, identifier, timestamp) { $this->logger->log(event, identifier, timestamp); }}class User extends LoggableObject { public function login() { //... $this->log(‘login’, $user->name, time()); }}Class Item extends LoggableObject { public function ship() { //... $this->log(‘login’, $item->id, time()); }}
  • 12. TRAITSWas, wenn wir einen zweiten Aspekt haben? User Item Verhalten: login() order() buy() ship() pay() changeColor() Aspekt: logging logging profiling profiling
  • 13. TRAITSVariante 1: Mehrfachvererbung log() profile() LoggableObject ProfilableObject User Item $this->log() $this->log()
  • 14. TRAITSVariante 1: Mehrfachvererbung log() profile() LoggableObject ProfilableObject User Item $this->log() $this->log()
  • 15. TRAITS Variante 2: Traits User Item $this->log() $this->log() use use use use log() profile()LoggerTrait ProfilingTrait
  • 16. TRAITStrait Logger { public function log(event, identifier, timestamp) {...}}trait Profiler { public function profile() {...}}class User { use Logger, Profiler; public function login() { $this->log(‘login’, $user->name, time()); $this->profile(...); }}Class Item { use Logger, Profiler; public function ship() { $this->log(‘login’, $item->id, time()); $this->profile(...); }}
  • 17. Danke. Fragen? @ManuelKiessling