Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Modernize Your PHP Code
Search
Anna Filina
June 10, 2015
Programming
350
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Modernize Your PHP Code
Anna Filina
June 10, 2015
More Decks by Anna Filina
See All by Anna Filina
Surviving a Symfony Upgrade
afilina
1
190
Upgrading Legacy to the Latest PHP Version
afilina
1
210
Better Code Design in PHP
afilina
0
320
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
210
Better Code Design in PHP
afilina
1
470
Better Code Design in PHP
afilina
0
630
Adding Tests to Untestable Legacy Code
afilina
0
420
Upgrading Legacy to the Latest PHP Version
afilina
0
440
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
340
Other Decks in Programming
See All in Programming
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
940
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
220
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
280
Datadog LLM Observabilityで実現する 安全なLLM Usage 管理
3150
0
130
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.6k
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
140
Vite+ Unified Toolchain for the Web
naokihaba
0
410
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
210
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
Performance Engineering for Everyone
elenatanasoiu
0
250
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
210
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
620
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Between Models and Reality
mayunak
4
360
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
340
Making Projects Easy
brettharned
120
6.7k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Rails Girls Zürich Keynote
gr2m
96
14k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
160
Bash Introduction
62gerente
615
220k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
600
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
190
Transcript
foolab.ca | @foolabca Modernize Your PHP Code IPC, Berlin -
June 10, 2015
Anna Filina • Developer • Problem solver • Teacher •
Advisor • FooLab + ConFoo 2
Objectives • Simplify code • Improve design • Increase maintainability
• Make coding more pleasant 3
Namespaces // 5.3 // Avoid name collisions between classes. $my_user
= new MyProject\Entity\User(); $lib_user = new SomeLibrary\Entity\User(); // Alias to long names. use Company\Project\Framework\Entity as Entity $user = new Entity\User(); // Try Composer! 4
Closures / Anonymous Functions // 5.3 // Assign to a
variable $filter_function = function($item) { ... }; 5
Closures / Anonymous Functions // Callback functions $products = array(
array("name" => "Skyrim", "price" => 30), array("name" => "Destiny", "price" => 50) ); $results = array_filter($products, function($item) { return $item["price"] <= 40; }); 6
Traits // 5.4 // Import groups of properties and methods
trait TextOverlay { function setText() { ... } function setFontSize() { ... } } trait ImageBackground { function setUrl() { ... } } class FacebookQuote { use TextOverlay; use ImageBackground; } 7
Finally // 5.5 // Practical if you want to execute
code whether there is or no exception. try { create_temp_file(); write_to_temp_file(); output_temp_file(); } catch(SomeException $e) { echo "Some error"; } finally { delete_temp_file(); } 8
Short Array Syntax // 5.4 // Hard to read a
complex structure. $products = array( array( "name" => "Skyrim", "price" => 30, "requirements" => array( "os" => array("Win XP", "Win Vista", "Win 7"), "ram" => 2048 ) ), array( "name" => "Diablo 3", "price" => 50, "requirements" => array( "os" => array("Win XP", "Win Vista", "Win 7", "Win 8"), "ram" => 1024 ) ) ); 9
Short Array Syntax $products = [ [ "name" => "Skyrim",
"price" => 30, "requirements" => [ "os" => [ "Win XP", "Win Vista", "Win 7" ], "ram" => 2048 ] ], [ "name" => "Diablo 3", "price" => 50, "requirements" => [ "os" => ["Win XP", "Win Vista", "Win 7", "Win 8"], "ram" => 1024 ] ] ]; 10
Password Functions // 5.5 $pass = password_hash("mypass", PASSWORD_BCRYPT, [ "cost"
=> 12, "salt" => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM) ]); // Between .25 et .50 seconds if (password_verify($form_password, $db_password)) {...} 11
Foreach With List // 5.5 $shape = [ [0, 0],
[2, 4], [4, 0] ]; foreach ($shape as list($x, $y)) { line_to_coords($x, $y); } 12
Argument Unpacking // 5.6 function addToCart($qty, $name, $price) {...} $product
= ["Civilization V", 40]; addToCart(1, ...$product); // addToCart(1, $product[0], $product[1]); 13
Anna Filina • Development: PHP, JS, etc. • Fix problems:
bugs, performance, etc. • Workshops: testing, Symfony, AngularJS, API, etc. • Advisor: testing strategy, legacy code, etc. 14
@afilina afilina.com