SlideShare una empresa de Scribd logo
1 de 61
Descargar para leer sin conexión
Hack the Future
Jason McCreary
"JMac"
@gonedark
Hack the Future - Jason McCreary - php[world] 2015
Talk the Talk
1. What is Hack?
2. Key Features of Hack
3. Unsupported PHP features in Hack
4. How can I use Hack?
5. Why Hack?
6. The Future
2
Hack the Future - Jason McCreary - php[world] 2015
But first…
A quick disclaimer.
3
Hack the Future - Jason McCreary - php[world] 2015
"Some things are going to be said."
4
Hack the Future - Jason McCreary - php[world] 2015
"This is not a talk to push Hack."
5
Hack the Future - Jason McCreary - php[world] 2015
"This is not a talk to shit on PHP."
6
Hack the Future - Jason McCreary - php[world] 2015
"This is a talk about the evolution of a language."
7
Hack the Future - Jason McCreary - php[world] 2015
What is Hack?
A very brief history.
8
Hack the Future - Jason McCreary - php[world] 2015
Brief History
• In 2009, Facebook released HipHop - a PHP compiler
• In 2010, Facebook introduced new features into PHP
• In 2012, Facebook began working on Hack
• In 2013, Facebook released HHVM - a HipHopVM
• In 2014, Facebook released Hack
9
Hack the Future - Jason McCreary - php[world] 2015
So what is Hack?
"Hack is a programming language for HHVM that
interoperates seamlessly with PHP."
10
Hack the Future - Jason McCreary - php[world] 2015
So what is Hack, really?
"Hack is a superset of PHP that runs on HHVM which
provides type checking."
11
Hack the Future - Jason McCreary - php[world] 2015
WTF Facebook?
Just use PHP.
12
Hack the Future - Jason McCreary - php[world] 2015
"Well, they do."
13
Hack the Future - Jason McCreary - php[world] 2015
"Facebook has millions of lines of PHP."
14
Hack the Future - Jason McCreary - php[world] 2015
"Instead of a rewrite or waiting or influencing the PHP
community, they made Hack."
15
Hack the Future - Jason McCreary - php[world] 2015
"The goal being to write cleaner, safer, and
refactorable code."
16
Hack the Future - Jason McCreary - php[world] 2015
Key Features
A deeper look at some of the features of Hack.
17
Hack the Future - Jason McCreary - php[world] 2015
Key Features in Hack
• Type Annotations
• Additional types
• Generics and Nullable
• Asynchronous programming
• Syntactic sugar
18
Hack the Future - Jason McCreary - php[world] 2015
Type Annotations
<?hh

// parameter type annotations
function output(string $str) {
echo 'Hello, ' . $str;
}
// return type annotations
function get_output(string $str): string {
return 'Hello, ' . $str;
}
19
Hack the Future - Jason McCreary - php[world] 2015
"Hack is not a statically typed language."
20
Hack the Future - Jason McCreary - php[world] 2015
"Hack allows more type hinting than PHP."
21
Hack the Future - Jason McCreary - php[world] 2015
"HHVM performs type checking before runtime which
ensures your code is type safe."
22
Hack the Future - Jason McCreary - php[world] 2015
Additional Types
• Collections
• Enums
• Shapes
• Tuples
• Custom Types
23
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
"In PHP, arrays are used for all the things!"
24
Hack the Future - Jason McCreary - php[world] 201525
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
<?php
// indexed, starting at 0
$arr1 = array(1, 2, 3);
// indexed, starting at 1
$arr2 = array(1 => 1, 2, 3);
// keyed, mix of integer keys and string keys
$arr3 = array("foo" => 1, 73 => 2, "bar" => 3);
// all array values are the same
26
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
"Primitive obsession is a code smell!"
27
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
"In PHP, arrays are primitives (i.e. non-objects)."
28
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
$ php -r 'var_dump(is_object(array()));'
bool(false)
29
Hack the Future - Jason McCreary - php[world] 2015
Collections
• Vector - an ordered, index collection
• Map - a key-based collection
• Set - an unordered, uniquely value collection
• Pair - an immutable, indexed, 2 element collection
• Both immutable and mutable versions
30
Hack the Future - Jason McCreary - php[world] 2015
Collections
<?hh


$vector = Vector {5, 10, 15};
$map = Map {"A" => 1, "B" => 2, "C" => 3};
$set = Set {"A", "B"};
31
Hack the Future - Jason McCreary - php[world] 2015
Enums
<?hh
enum DayOfWeek: int {
Sunday = 0;
Monday = 1;
Tuesday = 2;
Wednesday = 3;
Thursday = 4;
Friday = 5;
Saturday = 6;
}
echo DayOfWeek::Wednesday; // outputs 3
32
Hack the Future - Jason McCreary - php[world] 2015
Shapes
<?hh
// fixed size and type
// keyed collection of mixed values
$sh = shape('x' => 3, 'y' => 5);
echo $sh['x'] . ',' . $sh['y']; // outputs 3,5
33
Hack the Future - Jason McCreary - php[world] 2015
Tuples
<?hh
// fixed size and type, index array of mixed values
$tup = tuple('3', 2, 3, 4, 'hi');
echo $tup[1]; // outputs 2
unset($tup[0]); // error
$tup[5] = 'new value'; // error
$tup[4] = 'change value'; // ok, string to string
34
Hack the Future - Jason McCreary - php[world] 2015
Custom Types
<?hh

// define your own types
type MyInt = int;
type Point = (int, int);
35
Hack the Future - Jason McCreary - php[world] 2015
Generics and Nullable
• Generics - ability to parameterize the type of a class
or method and declare it upon instantiation
• Nullable - ability to declare a type allows null
36
Hack the Future - Jason McCreary - php[world] 2015
Generics
<?hh
class Box<T> {
protected T $data;
public function __construct(T $data) {
$this->data = $data;
}
public function getData(): T {
return $this->data;
}
}
37
Hack the Future - Jason McCreary - php[world] 2015
Nullable
<?hh
function check_not_null(?int $x): int {
if ($x === null) {
return -1;
} else {
return $x;
}
}
38
Hack the Future - Jason McCreary - php[world] 2015
Asynchronous Programming
<?hh
async function helloAfter($name, $timeout): Awaitable<string> {
await SleepWaitHandle::create($timeout * 1000000);
echo sprintf("hello %sn", $name);
}
async function run() {
$joe = helloAfter('Joe', 3);
$mike = helloAfter('Mike', 1);
await GenArrayWaitHandle::create(array($joe, $mike));
}
run()->join();
// prints:
// hello Mike
// hello Joe
39
Hack the Future - Jason McCreary - php[world] 2015
Syntactic Sugar
• Constructor Argument Promotion
• Lambdas
40
Hack the Future - Jason McCreary - php[world] 2015
Constructor Argument Promotion
<?php
class Person {
private string $name;
private int $age;
public function __construct(string $name, int $age) {
$this->name = $name;
$this->age = $age;
}
}
41
Hack the Future - Jason McCreary - php[world] 2015
Constructor Argument Promotion
<?hh
class Person {
public function __construct(public string $name,
protected int $age) {}
}
42
Hack the Future - Jason McCreary - php[world] 2015
Lambdas
<?php
$foo = function($x) {
return $x + 1;
}
$foo(12); // returns 13
$squared = array_map(function($x) {
return $x * $x;
}, array(1,2,3));
var_dump($squared); // $squared is array(1,4,9)
43
Hack the Future - Jason McCreary - php[world] 2015
Lambdas
<?hh
$foo = $x ==> $x + 1;
$foo(12); // returns 13
$squared = array_map($x ==> $x * $x, array(1,2,3));
var_dump($squared); // $squared is array(1,4,9)
44
Hack the Future - Jason McCreary - php[world] 2015
Unsupported PHP Features
The things Hack no likey.
45
Hack the Future - Jason McCreary - php[world] 2015
Unsupported PHP Features
• Alternative syntaxes: AND, OR, XOR, endif, etc.
• Dynamic features: eval, continue n, break n,

$$var, $obj->{$var}
• Top Level Code
• References
• Globals
• Case insensitive function calls
• Explicitly named constructors
46
Hack the Future - Jason McCreary - php[world] 2015
How can I use Hack?
What you need to do to start Hack’in.
47
Hack the Future - Jason McCreary - php[world] 2015
"Change <?php to <?hh"
48
Hack the Future - Jason McCreary - php[world] 2015
"You’re right, first install HHVM."
49
Hack the Future - Jason McCreary - php[world] 2015
"Then change <?php to <?hh!"
50
Hack the Future - Jason McCreary - php[world] 2015
Hack Modes
• Hack has three modes: strict, partial, and
decl
• strict - type checker will catch every type error
• partial - type checker checks code that uses types
• decl - allows strict code to call separate, legacy
code
• The default is partial
51
Hack the Future - Jason McCreary - php[world] 2015
Hack Modes
<?hh // strict
function example(int $x) {
echo "I'm so strict!";
}
52
Hack the Future - Jason McCreary - php[world] 2015
Why Hack?
Some reasons for using Hack.
53
Hack the Future - Jason McCreary - php[world] 2015
Reasons to Hack
• Code clarity
• Performance
• Language features, like Asynchronous Programming
• Evolution
54
Hack the Future - Jason McCreary - php[world] 2015
The Future
So bright, I gotta wear shades.
55
Hack the Future - Jason McCreary - php[world] 2015
Some things in PHP
• Variadic functions (PHP 5.6)
• Scalar type declarations (PHP 7)
• Return type declarations (PHP 7)
• Null coalesce operator (PHP 7)
• Deprecations: alternative syntax and named
constructors (PHP 7)
56
Hack the Future - Jason McCreary - php[world] 2015
Look familiar?
<?php
function add(int $x, int $y): int {
return $x + $y;
}
$nil = null;
$foo = $nil ?? add(2, 3);
57
Hack the Future - Jason McCreary - php[world] 2015
"Yeah, Hack had it first."
58
Hack the Future - Jason McCreary - php[world] 2015
"Hack, coming soon in PHP 7+."
59
Hack the Future - Jason McCreary - php[world] 2015
"This is evolution."
60
Hack the Future - Jason McCreary - php[world] 2015
Questions…
Ask now or tweet me @gonedark.
61

Más contenido relacionado

La actualidad más candente

Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialJoe Ferguson
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web ArtisansRaf Kewl
 
All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$Joe Ferguson
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New FeaturesJoe Ferguson
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 Joe Ferguson
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionJoe Ferguson
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionJoe Ferguson
 
Laravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureLaravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureShawn McCool
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Lorvent56
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5Soheil Khodayari
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel frameworkPhu Luong Trong
 

La actualidad más candente (20)

Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Workshop Laravel 5.2
Workshop Laravel 5.2Workshop Laravel 5.2
Workshop Laravel 5.2
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Laravel 5.4
Laravel 5.4 Laravel 5.4
Laravel 5.4
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
Laravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureLaravel.IO A Use-Case Architecture
Laravel.IO A Use-Case Architecture
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 

Destacado

Zend Framework Foundations
Zend Framework FoundationsZend Framework Foundations
Zend Framework FoundationsChuck Reeves
 
Amp your site an intro to accelerated mobile pages
Amp your site  an intro to accelerated mobile pagesAmp your site  an intro to accelerated mobile pages
Amp your site an intro to accelerated mobile pagesRobert McFrazier
 
php[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Upphp[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground UpJoe Ferguson
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...James Titcumb
 
Presentation Bulgaria PHP
Presentation Bulgaria PHPPresentation Bulgaria PHP
Presentation Bulgaria PHPAlena Holligan
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Joe Ferguson
 
Dip Your Toes in the Sea of Security
Dip Your Toes in the Sea of SecurityDip Your Toes in the Sea of Security
Dip Your Toes in the Sea of SecurityJames Titcumb
 
Code Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsCode Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsDana Luther
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLGabriela Ferrara
 
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix ItPHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix ItMatt Toigo
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHPDavid Stockton
 
Enough suffering, fix your architecture!
Enough suffering, fix your architecture!Enough suffering, fix your architecture!
Enough suffering, fix your architecture!Luís Cobucci
 
Website Accessibility: It’s the Right Thing to do
Website Accessibility: It’s the Right Thing to doWebsite Accessibility: It’s the Right Thing to do
Website Accessibility: It’s the Right Thing to doDesignHammer
 

Destacado (20)

Zend Framework Foundations
Zend Framework FoundationsZend Framework Foundations
Zend Framework Foundations
 
Amp your site an intro to accelerated mobile pages
Amp your site  an intro to accelerated mobile pagesAmp your site  an intro to accelerated mobile pages
Amp your site an intro to accelerated mobile pages
 
Create, test, secure, repeat
Create, test, secure, repeatCreate, test, secure, repeat
Create, test, secure, repeat
 
php[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Upphp[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Up
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
 
Engineer - Mastering the Art of Software
Engineer - Mastering the Art of SoftwareEngineer - Mastering the Art of Software
Engineer - Mastering the Art of Software
 
Presentation Bulgaria PHP
Presentation Bulgaria PHPPresentation Bulgaria PHP
Presentation Bulgaria PHP
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
 
Dip Your Toes in the Sea of Security
Dip Your Toes in the Sea of SecurityDip Your Toes in the Sea of Security
Dip Your Toes in the Sea of Security
 
Code Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsCode Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application Migrations
 
Git Empowered
Git EmpoweredGit Empowered
Git Empowered
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Conscious Coupling
Conscious CouplingConscious Coupling
Conscious Coupling
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQL
 
200K+ reasons security is a must
200K+ reasons security is a must200K+ reasons security is a must
200K+ reasons security is a must
 
Modern sql
Modern sqlModern sql
Modern sql
 
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix ItPHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHP
 
Enough suffering, fix your architecture!
Enough suffering, fix your architecture!Enough suffering, fix your architecture!
Enough suffering, fix your architecture!
 
Website Accessibility: It’s the Right Thing to do
Website Accessibility: It’s the Right Thing to doWebsite Accessibility: It’s the Right Thing to do
Website Accessibility: It’s the Right Thing to do
 

Similar a Hack Future PHP Evolution

PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?Sam Thomas
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpMichael Girouard
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4Wim Godden
 
501 - PHP MYSQL.pdf
501 - PHP MYSQL.pdf501 - PHP MYSQL.pdf
501 - PHP MYSQL.pdfAkashGohil10
 
Dip Your Toes in the Sea of Security (PHP UK 2016)
Dip Your Toes in the Sea of Security (PHP UK 2016)Dip Your Toes in the Sea of Security (PHP UK 2016)
Dip Your Toes in the Sea of Security (PHP UK 2016)James Titcumb
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php SecurityDave Ross
 
How to write not breakable unit tests
How to write not breakable unit testsHow to write not breakable unit tests
How to write not breakable unit testsRafal Ksiazek
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоGeeksLab Odessa
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Chris Tankersley
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress DeveloperJoey Kudish
 
Modern Web Development in Perl
Modern Web Development in PerlModern Web Development in Perl
Modern Web Development in PerlJason Crome
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015jbandi
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesLeo Loobeek
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)Oleg Zinchenko
 

Similar a Hack Future PHP Evolution (20)

2009-02 Oops!
2009-02 Oops!2009-02 Oops!
2009-02 Oops!
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented Php
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
501 - PHP MYSQL.pdf
501 - PHP MYSQL.pdf501 - PHP MYSQL.pdf
501 - PHP MYSQL.pdf
 
Dip Your Toes in the Sea of Security (PHP UK 2016)
Dip Your Toes in the Sea of Security (PHP UK 2016)Dip Your Toes in the Sea of Security (PHP UK 2016)
Dip Your Toes in the Sea of Security (PHP UK 2016)
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php Security
 
How to write not breakable unit tests
How to write not breakable unit testsHow to write not breakable unit tests
How to write not breakable unit tests
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 
Modern Web Development in Perl
Modern Web Development in PerlModern Web Development in Perl
Modern Web Development in Perl
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying Techniques
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)
 

Más de Jason McCreary

Patterns, Code Smells, and The Pragmattic Programmer
Patterns, Code Smells, and The Pragmattic ProgrammerPatterns, Code Smells, and The Pragmattic Programmer
Patterns, Code Smells, and The Pragmattic ProgrammerJason McCreary
 
Cache, Workers, and Queues
Cache, Workers, and QueuesCache, Workers, and Queues
Cache, Workers, and QueuesJason McCreary
 
21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast21 Ways to Make WordPress Fast
21 Ways to Make WordPress FastJason McCreary
 
21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast21 Ways to Make WordPress Fast
21 Ways to Make WordPress FastJason McCreary
 
Configuring WordPress for Multiple Environments
Configuring WordPress for Multiple EnvironmentsConfiguring WordPress for Multiple Environments
Configuring WordPress for Multiple EnvironmentsJason McCreary
 

Más de Jason McCreary (6)

BDD in iOS with Cedar
BDD in iOS with CedarBDD in iOS with Cedar
BDD in iOS with Cedar
 
Patterns, Code Smells, and The Pragmattic Programmer
Patterns, Code Smells, and The Pragmattic ProgrammerPatterns, Code Smells, and The Pragmattic Programmer
Patterns, Code Smells, and The Pragmattic Programmer
 
Cache, Workers, and Queues
Cache, Workers, and QueuesCache, Workers, and Queues
Cache, Workers, and Queues
 
21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast
 
21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast
 
Configuring WordPress for Multiple Environments
Configuring WordPress for Multiple EnvironmentsConfiguring WordPress for Multiple Environments
Configuring WordPress for Multiple Environments
 

Último

TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 

Último (11)

TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 

Hack Future PHP Evolution

  • 1. Hack the Future Jason McCreary "JMac" @gonedark
  • 2. Hack the Future - Jason McCreary - php[world] 2015 Talk the Talk 1. What is Hack? 2. Key Features of Hack 3. Unsupported PHP features in Hack 4. How can I use Hack? 5. Why Hack? 6. The Future 2
  • 3. Hack the Future - Jason McCreary - php[world] 2015 But first… A quick disclaimer. 3
  • 4. Hack the Future - Jason McCreary - php[world] 2015 "Some things are going to be said." 4
  • 5. Hack the Future - Jason McCreary - php[world] 2015 "This is not a talk to push Hack." 5
  • 6. Hack the Future - Jason McCreary - php[world] 2015 "This is not a talk to shit on PHP." 6
  • 7. Hack the Future - Jason McCreary - php[world] 2015 "This is a talk about the evolution of a language." 7
  • 8. Hack the Future - Jason McCreary - php[world] 2015 What is Hack? A very brief history. 8
  • 9. Hack the Future - Jason McCreary - php[world] 2015 Brief History • In 2009, Facebook released HipHop - a PHP compiler • In 2010, Facebook introduced new features into PHP • In 2012, Facebook began working on Hack • In 2013, Facebook released HHVM - a HipHopVM • In 2014, Facebook released Hack 9
  • 10. Hack the Future - Jason McCreary - php[world] 2015 So what is Hack? "Hack is a programming language for HHVM that interoperates seamlessly with PHP." 10
  • 11. Hack the Future - Jason McCreary - php[world] 2015 So what is Hack, really? "Hack is a superset of PHP that runs on HHVM which provides type checking." 11
  • 12. Hack the Future - Jason McCreary - php[world] 2015 WTF Facebook? Just use PHP. 12
  • 13. Hack the Future - Jason McCreary - php[world] 2015 "Well, they do." 13
  • 14. Hack the Future - Jason McCreary - php[world] 2015 "Facebook has millions of lines of PHP." 14
  • 15. Hack the Future - Jason McCreary - php[world] 2015 "Instead of a rewrite or waiting or influencing the PHP community, they made Hack." 15
  • 16. Hack the Future - Jason McCreary - php[world] 2015 "The goal being to write cleaner, safer, and refactorable code." 16
  • 17. Hack the Future - Jason McCreary - php[world] 2015 Key Features A deeper look at some of the features of Hack. 17
  • 18. Hack the Future - Jason McCreary - php[world] 2015 Key Features in Hack • Type Annotations • Additional types • Generics and Nullable • Asynchronous programming • Syntactic sugar 18
  • 19. Hack the Future - Jason McCreary - php[world] 2015 Type Annotations <?hh
 // parameter type annotations function output(string $str) { echo 'Hello, ' . $str; } // return type annotations function get_output(string $str): string { return 'Hello, ' . $str; } 19
  • 20. Hack the Future - Jason McCreary - php[world] 2015 "Hack is not a statically typed language." 20
  • 21. Hack the Future - Jason McCreary - php[world] 2015 "Hack allows more type hinting than PHP." 21
  • 22. Hack the Future - Jason McCreary - php[world] 2015 "HHVM performs type checking before runtime which ensures your code is type safe." 22
  • 23. Hack the Future - Jason McCreary - php[world] 2015 Additional Types • Collections • Enums • Shapes • Tuples • Custom Types 23
  • 24. Hack the Future - Jason McCreary - php[world] 2015 The problem with array "In PHP, arrays are used for all the things!" 24
  • 25. Hack the Future - Jason McCreary - php[world] 201525
  • 26. Hack the Future - Jason McCreary - php[world] 2015 The problem with array <?php // indexed, starting at 0 $arr1 = array(1, 2, 3); // indexed, starting at 1 $arr2 = array(1 => 1, 2, 3); // keyed, mix of integer keys and string keys $arr3 = array("foo" => 1, 73 => 2, "bar" => 3); // all array values are the same 26
  • 27. Hack the Future - Jason McCreary - php[world] 2015 The problem with array "Primitive obsession is a code smell!" 27
  • 28. Hack the Future - Jason McCreary - php[world] 2015 The problem with array "In PHP, arrays are primitives (i.e. non-objects)." 28
  • 29. Hack the Future - Jason McCreary - php[world] 2015 The problem with array $ php -r 'var_dump(is_object(array()));' bool(false) 29
  • 30. Hack the Future - Jason McCreary - php[world] 2015 Collections • Vector - an ordered, index collection • Map - a key-based collection • Set - an unordered, uniquely value collection • Pair - an immutable, indexed, 2 element collection • Both immutable and mutable versions 30
  • 31. Hack the Future - Jason McCreary - php[world] 2015 Collections <?hh 
 $vector = Vector {5, 10, 15}; $map = Map {"A" => 1, "B" => 2, "C" => 3}; $set = Set {"A", "B"}; 31
  • 32. Hack the Future - Jason McCreary - php[world] 2015 Enums <?hh enum DayOfWeek: int { Sunday = 0; Monday = 1; Tuesday = 2; Wednesday = 3; Thursday = 4; Friday = 5; Saturday = 6; } echo DayOfWeek::Wednesday; // outputs 3 32
  • 33. Hack the Future - Jason McCreary - php[world] 2015 Shapes <?hh // fixed size and type // keyed collection of mixed values $sh = shape('x' => 3, 'y' => 5); echo $sh['x'] . ',' . $sh['y']; // outputs 3,5 33
  • 34. Hack the Future - Jason McCreary - php[world] 2015 Tuples <?hh // fixed size and type, index array of mixed values $tup = tuple('3', 2, 3, 4, 'hi'); echo $tup[1]; // outputs 2 unset($tup[0]); // error $tup[5] = 'new value'; // error $tup[4] = 'change value'; // ok, string to string 34
  • 35. Hack the Future - Jason McCreary - php[world] 2015 Custom Types <?hh
 // define your own types type MyInt = int; type Point = (int, int); 35
  • 36. Hack the Future - Jason McCreary - php[world] 2015 Generics and Nullable • Generics - ability to parameterize the type of a class or method and declare it upon instantiation • Nullable - ability to declare a type allows null 36
  • 37. Hack the Future - Jason McCreary - php[world] 2015 Generics <?hh class Box<T> { protected T $data; public function __construct(T $data) { $this->data = $data; } public function getData(): T { return $this->data; } } 37
  • 38. Hack the Future - Jason McCreary - php[world] 2015 Nullable <?hh function check_not_null(?int $x): int { if ($x === null) { return -1; } else { return $x; } } 38
  • 39. Hack the Future - Jason McCreary - php[world] 2015 Asynchronous Programming <?hh async function helloAfter($name, $timeout): Awaitable<string> { await SleepWaitHandle::create($timeout * 1000000); echo sprintf("hello %sn", $name); } async function run() { $joe = helloAfter('Joe', 3); $mike = helloAfter('Mike', 1); await GenArrayWaitHandle::create(array($joe, $mike)); } run()->join(); // prints: // hello Mike // hello Joe 39
  • 40. Hack the Future - Jason McCreary - php[world] 2015 Syntactic Sugar • Constructor Argument Promotion • Lambdas 40
  • 41. Hack the Future - Jason McCreary - php[world] 2015 Constructor Argument Promotion <?php class Person { private string $name; private int $age; public function __construct(string $name, int $age) { $this->name = $name; $this->age = $age; } } 41
  • 42. Hack the Future - Jason McCreary - php[world] 2015 Constructor Argument Promotion <?hh class Person { public function __construct(public string $name, protected int $age) {} } 42
  • 43. Hack the Future - Jason McCreary - php[world] 2015 Lambdas <?php $foo = function($x) { return $x + 1; } $foo(12); // returns 13 $squared = array_map(function($x) { return $x * $x; }, array(1,2,3)); var_dump($squared); // $squared is array(1,4,9) 43
  • 44. Hack the Future - Jason McCreary - php[world] 2015 Lambdas <?hh $foo = $x ==> $x + 1; $foo(12); // returns 13 $squared = array_map($x ==> $x * $x, array(1,2,3)); var_dump($squared); // $squared is array(1,4,9) 44
  • 45. Hack the Future - Jason McCreary - php[world] 2015 Unsupported PHP Features The things Hack no likey. 45
  • 46. Hack the Future - Jason McCreary - php[world] 2015 Unsupported PHP Features • Alternative syntaxes: AND, OR, XOR, endif, etc. • Dynamic features: eval, continue n, break n,
 $$var, $obj->{$var} • Top Level Code • References • Globals • Case insensitive function calls • Explicitly named constructors 46
  • 47. Hack the Future - Jason McCreary - php[world] 2015 How can I use Hack? What you need to do to start Hack’in. 47
  • 48. Hack the Future - Jason McCreary - php[world] 2015 "Change <?php to <?hh" 48
  • 49. Hack the Future - Jason McCreary - php[world] 2015 "You’re right, first install HHVM." 49
  • 50. Hack the Future - Jason McCreary - php[world] 2015 "Then change <?php to <?hh!" 50
  • 51. Hack the Future - Jason McCreary - php[world] 2015 Hack Modes • Hack has three modes: strict, partial, and decl • strict - type checker will catch every type error • partial - type checker checks code that uses types • decl - allows strict code to call separate, legacy code • The default is partial 51
  • 52. Hack the Future - Jason McCreary - php[world] 2015 Hack Modes <?hh // strict function example(int $x) { echo "I'm so strict!"; } 52
  • 53. Hack the Future - Jason McCreary - php[world] 2015 Why Hack? Some reasons for using Hack. 53
  • 54. Hack the Future - Jason McCreary - php[world] 2015 Reasons to Hack • Code clarity • Performance • Language features, like Asynchronous Programming • Evolution 54
  • 55. Hack the Future - Jason McCreary - php[world] 2015 The Future So bright, I gotta wear shades. 55
  • 56. Hack the Future - Jason McCreary - php[world] 2015 Some things in PHP • Variadic functions (PHP 5.6) • Scalar type declarations (PHP 7) • Return type declarations (PHP 7) • Null coalesce operator (PHP 7) • Deprecations: alternative syntax and named constructors (PHP 7) 56
  • 57. Hack the Future - Jason McCreary - php[world] 2015 Look familiar? <?php function add(int $x, int $y): int { return $x + $y; } $nil = null; $foo = $nil ?? add(2, 3); 57
  • 58. Hack the Future - Jason McCreary - php[world] 2015 "Yeah, Hack had it first." 58
  • 59. Hack the Future - Jason McCreary - php[world] 2015 "Hack, coming soon in PHP 7+." 59
  • 60. Hack the Future - Jason McCreary - php[world] 2015 "This is evolution." 60
  • 61. Hack the Future - Jason McCreary - php[world] 2015 Questions… Ask now or tweet me @gonedark. 61