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
180
Upgrading Legacy to the Latest PHP Version
afilina
1
200
Better Code Design in PHP
afilina
0
310
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
210
Better Code Design in PHP
afilina
1
460
Better Code Design in PHP
afilina
0
630
Adding Tests to Untestable Legacy Code
afilina
0
410
Upgrading Legacy to the Latest PHP Version
afilina
0
430
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
340
Other Decks in Programming
See All in Programming
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
560
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
120
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
530
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
120
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
20
6.4k
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
240
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
120
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
190
A2UI という光を覗いてみる
satohjohn
1
120
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
5
3.7k
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
110
Claspは野良GASの夢をみるか
takter00
0
180
Featured
See All Featured
How to build a perfect <img>
jonoalderson
1
5.6k
Raft: Consensus for Rubyists
vanstee
141
7.5k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
220
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
What's in a price? How to price your products and services
michaelherold
247
13k
WENDY [Excerpt]
tessaabrams
11
38k
Site-Speed That Sticks
csswizardry
13
1.2k
Accessibility Awareness
sabderemane
1
140
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
580
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.4k
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