SlideShare a Scribd company logo
Hack Tutorial
吉澤和香奈
自己紹介
↳ 吉澤和香奈
↳ カツラじゃありません
↳ 1987/6/30生まれO型
↳ PHPに出会ったのは2012
年の夏です
↳ HNは「wakana」「わかな
だょ〜」「ブ〜バ〜」等、気
分により多数あります
Hackとは
Facebookが作った
PHPを拡張した
静的型検査する
プログラミング言語です
Facebookが作った
PHPを拡張した
静的型検査する
プログラミング言語です
→型に強いです
HHVMとは
PHP/Hackをバイナリコードに
変換させるVMです
(HipHop Virtual Machine)
PHP/Hackをバイナリコードに
変換させるVMです
(HipHop Virtual Machine)
→読み込みが早くなります
HHVMで
PHPと
Hackの
共存が実現できます!!
簡単に移行が実現できそうです
Tutorialやってみました
Hack Tutorial(公式)
http://hacklang.org/tutorial/
2015/1/26現在のものです
Exercise 1
/***************************************************/
/****************** Hack Tutorial ******************/
/***************************************************/
/************ Click 'Next' to get started! *********/
Exercise 2
<?php
// ^-- FIXME: replace <?php with <?hh
// A Hack file always starts with <?hh
<?hh
// ^-- FIXME: replace <?php with <?hh
// A Hack file always starts with <?hh
Exercise 3
<?hh
// Hack functions are annotated with types.
function my_negation(bool $x): bool {
return !$x;
}
// FIXME: annotate this function parameter
// and return with the type 'int'.
function add_one(/* TODO */ $x): /* TODO */ {
return $x+1;
}
<?hh
// Hack functions are annotated with types.
function my_negation(bool $x): bool {
return !$x;
}
// FIXME: annotate this function parameter
// and return with the type 'int'.
function add_one(int $x): int {
return $x+1;
}
Exercise 4
<?hh
/* Hack errors come in multiple parts.
* Hover over the underlined parts!
*/
function add_one(int $x): int {
return $x+1;
}
function test(): void {
$my_string = 'hello';
// Some clever code ...
add_one($my_string);
}
<?hh
/* Hack errors come in multiple parts.
* Hover over the underlined parts!
*/
function add_one(int $x): int {
return $x+1;
}
function test(): void {
$my_string = 'hello';
// Some clever code ...
add_one((int) $my_string);
}
Exercise 5
<?hh
// Prefixing a type with '?' permits null.
// TODO: fix the type of the parameter $x to permit null.
function f(int $x): void {
var_dump($x);
}
function test(): void {
f(123);
f(null);
}
<?hh
// Prefixing a type with '?' permits null.
// TODO: fix the type of the parameter $x to permit null.
function f(?int $x): void {
var_dump($x);
}
function test(): void {
f(123);
f(null);
}
Exercise 6
<?hh
interface User { public function getName(): string; }
function get_user_name(?User $user): string {
if($user !== null) {
// We checked that $user was not null.
// Its type is now 'User'.
/* TODO: return $user->getName() */
}
return '<invalid name>';
}
function test(User $user) {
$name1 = get_user_name($user);
$name2 = get_user_name(null);
}
<?hh
interface User { public function getName(): string; }
function get_user_name(?User $user): string {
if($user !== null) {
// We checked that $user was not null.
// Its type is now 'User'.
return $user->getName();
}
return '<invalid name>';
}
function test(User $user) {
$name1 = get_user_name($user);
$name2 = get_user_name(null);
}
Exercise 7
<?hh
interface User { public function getName(): string; }
// There are many ways to handle null values.
// Throwing an exception is one of them.
function get_user_name(?User $user): string {
if($user === null) {
throw new RuntimeException('Invalid user name');
}
/* TODO: return $user->getName() */
}
function test(User $user) {
$name1 = get_user_name($user);
$name2 = get_user_name(null);
}
<?hh
interface User { public function getName(): string; }
// There are many ways to handle null values.
// Throwing an exception is one of them.
function get_user_name(?User $user): string {
if($user === null) {
throw new RuntimeException('Invalid user name');
}
return $user->getName();
}
function test(User $user) {
$name1 = get_user_name($user);
$name2 = get_user_name(null);
}
Exercise 8
<?hh
// Hack introduces new collection types (Vector, Set and Map).
function test(): int {
// Vector is preferred over array(1, 2, 3)
$vector = Vector {1, 2, 3};
$sum = 0;
foreach ($vector as $val) {
$sum += $val;
}
return $sum;
}
<?hh
// Hack introduces new collection types (Vector, Set and Map).
function test(): int {
// Vector is preferred over array(1, 2, 3)
$vector = Vector {1, 2, 3};
$sum = 0;
foreach ($vector as $val) {
$sum += $val;
}
return $sum;
}
// Arrayよりも高速なVectorが使えます
Exercise 9
<?hh
// Hack uses generics for Collection types.
// TODO: fix the return type of the function 'test'
function test(): Vector<string> {
$vector = Vector {1, 2, 3};
return $vector;
}
<?hh
// Hack uses generics for Collection types.
// TODO: fix the return type of the function 'test'
function test(): Vector<string> {
$vector = Vector {“1”, “2”, “3”};
return $vector;
}
Exercise 10
<?hh
function vector_add1(Vector<int> $v): Vector<int> {
// Example of lambda expressions.
return $v->map($x ==> $x + 1);
}
function vector_mult2(Vector<int> $v): Vector<int> {
// TODO: write a function multiplying all the elements by 2
}
<?hh
function vector_add1(Vector<int> $v): Vector<int> {
// Example of lambda expressions.
return $v->map($x ==> $x + 1);
}
function vector_mult2(Vector<int> $v): Vector<int> {
// TODO: write a function multiplying all the elements by 2
return $v->map($x ==> $x * 2);
}
Exercise 11
/*
* Congratulations!
* You completed the beginner's tutorial.
*
* Click next to continue in expert mode.
*/
Exercise 12
<?hh
// All the members of a class must be initialized
class Point {
private float $x;
private float $y;
public function __construct(float $x, float $y) {
$this->x = $x;
// FIXME: initalize the member 'y'
}
}
<?hh
// All the members of a class must be initialized
class Point {
private float $x;
private float $y;
public function __construct(float $x, float $y) {
$this->x = $x;
// FIXME: initalize the member 'y'
$this->y = $y;
}
}
Exercise 13
<?hh
// Check out this new syntax!
// It's shorter and does the same thing ...
class Point {
public function __construct(
private float $x,
private float $y
) {}
}
<?hh
// Check out this new syntax!
// It's shorter and does the same thing ...
class Point {
public function __construct(
private float $x,
private float $y
) {}
}
// このような新しい書き方で今までより短くなります
Exercise 14
<?hh
// You can create your own generics!
class Store<T> {
public function __construct(private T $data) {}
public function get(): T { return $this->data; }
public function set(T $x): void { $this->data = $x; }
}
// TODO: fix the return type of the function test
function test(): Store<int> {
$data = 'Hello world!';
$x = new Store($data);
return $x;
}
<?hh
// You can create your own generics!
class Store<T> {
public function __construct(private T $data) {}
public function get(): T { return $this->data; }
public function set(T $x): void { $this->data = $x; }
}
// TODO: fix the return type of the function test
function test(): Store<string> {
$data = 'Hello world!';
$x = new Store($data);
return $x;
}
Exercise 15
<?hh
// You can specify constraints on generics.
interface MyInterface {
public function foo(): void;
}
// TODO: uncomment 'as MyInterface'
// T as MyInterface means any object as long as
// it implements MyInterface
function call_foo<T /* as MyInterface */>(T $x): T {
$x->foo();
return $x;
}
<?hh
// You can specify constraints on generics.
interface MyInterface {
public function foo(): void;
}
// TODO: uncomment 'as MyInterface'
// T as MyInterface means any object as long as
// it implements MyInterface
function call_foo<T as MyInterface>(T $x): T {
$x->foo();
return $x;
}
Exercise 16
<?hh
// The type 'this' always points to the most derived type
class MyBaseClass {
protected int $count = 0;
// TODO: replace 'MyBaseClass' by 'this'
public function add1(): MyBaseClass {
$this->count += 1;
return $this;
}
}
class MyDerivedClass extends MyBaseClass {
public function print_count(): void { echo $this->count; }
}
function test(): void {
$x = new MyDerivedClass();
$x->add1()->print_count();
}
<?hh
// The type 'this' always points to the most derived type
class MyBaseClass {
protected int $count = 0;
// TODO: replace 'MyBaseClass' by 'this'
public function add1(): this {
$this->count += 1;
return $this;
}
}
class MyDerivedClass extends MyBaseClass {
public function print_count(): void { echo $this->count; }
}
function test(): void {
$x = new MyDerivedClass();
$x->add1()->print_count();
}
Exercise 17
<?hh
// When a type is too long, you can use a type alias.
type Matrix<T> = Vector<Vector<T>>;
function first_row<T>(Matrix<T> $matrix): Vector<T> {
return $matrix[0];
}
<?hh
// When a type is too long, you can use a type alias.
type Matrix<T> = Vector<Vector<T>>;
function first_row<T>(Matrix<T> $matrix): Vector<T> {
return $matrix[0];
}
// タイプが長い時は別名を指定出来ます
Exercise 18
<?hh
// Tuples represent fixed size arrays.
// TODO: fix the return type.
function my_first_pair((int, bool) $pair): int {
list($_, $result) = $pair;
return $result;
}
<?hh
// Tuples represent fixed size arrays.
// TODO: fix the return type.
function my_first_pair((int, bool) $pair): int {
list($result, $_) = $pair;
return $result;
}
Exercise 19
<?hh
// Shapes can be used for arrays with constant string keys.
type my_shape = shape(
'field1' => int,
'field2' => bool,
);
function first_shape(): my_shape {
$result = shape('field1' => 1);
// TODO: set 'field2' to the value true
// on $result to complete the shape.
return $result;
}
<?hh
// Shapes can be used for arrays with constant string keys.
type my_shape = shape(
'field1' => int,
'field2' => bool,
);
function first_shape(): my_shape {
$result = my_shape(1, true);
// TODO: set 'field2' to the value true
// on $result to complete the shape.
return $result;
}
Exercise 20
<?hh
// You can specify the types of functions too.
function apply_int<T>((function(int): T) $callback, int $value): T {
// TODO: return $callback($value)
}
<?hh
// You can specify the types of functions too.
function apply_int<T>((function(int): T) $callback, int $value): T {
return $callback($value);
}
Exercise 21
<?hh
// XHP is useful to build html (or xml) elements.
// The escaping is done automatically, it is important to avoid
// security issues (XSS attacks).
function build_paragraph(string $text, string $style): :div {
return
<div style={$style}>
<p>{$text}</p>
</div>;
}
<?hh
// XHP is useful to build html (or xml) elements.
// The escaping is done automatically, it is important to avoid
// security issues (XSS attacks).
function build_paragraph(string $text, string $style): :div {
return
<div style={$style}>
<p>{$text}</p>
</div>;
}
// XHP記法でHTMLまたはXMLを構築することにより、クロスサイトスクリプティング対
策が実現できます
Exercise 22
<?hh
/* Opaque types let you hide the representation of a type.
*
* The definition below introduces the new type 'user_id'
* that will only be compatible with 'int' within this file.
* Outside of this file, 'user_id' becomes "opaque"; it won't
* be compatible with 'int' anymore.
*/
newtype user_id = int;
function make_user_id(int $x): user_id {
// Do some checks ...
return $x;
}
// You should only use this function for rendering
function user_id_to_int(user_id $x): int {
return $x;
}
<?hh
/* Opaque types let you hide the representation of a type.
*
* The definition below introduces the new type 'user_id'
* that will only be compatible with 'int' within this file.
* Outside of this file, 'user_id' becomes "opaque"; it won't
* be compatible with 'int' anymore.
*/
newtype user_id = int;
function make_user_id(int $x): user_id {
// Do some checks ...
return $x;
}
// You should only use this function for rendering
function user_id_to_int(user_id $x): int {
return $x;
}
// user_idタイプを作る事により、このファイルで型を管理し、他のファイルではuser_id型になります
Exercise 23
<?hh
class MyBaseClass {
// TODO: fix the typo in the name of the method.
public function get_uuser(): MyUser {
return new MyUser();
}
}
class MyDerivedClass extends MyBaseClass {
/* <<Override>> is used to specify that get_user has been inherited.
* When that's not the case, Hack gives an error.
*/
<<Override>> public function get_user(): MyUser {
return new MyUser();
}
}
<?hh
class MyBaseClass {
// TODO: fix the typo in the name of the method.
public function get_user(): MyUser {
return new MyUser();
}
}
class MyDerivedClass extends MyBaseClass {
/* <<Override>> is used to specify that get_user has been inherited.
* When that's not the case, Hack gives an error.
*/
<<Override>> public function get_user(): MyUser {
return new MyUser();
}
}
Exercise 24
<?hh
class C { protected function bar(): void {} }
interface I { public function foo(): void; }
// 'require' lets you specify what the trait needs to work properly.
trait T {
// The class using the trait must extend 'C'
require extends C;
// TODO: uncomment the next line to fix the error
// require implements I;
public function do_stuff(): void {
$this->bar(); // We can access bar because we used "require extends"
$this->foo();
}
}
<?hh
class C { protected function bar(): void {} }
interface I { public function foo(): void; }
// 'require' lets you specify what the trait needs to work properly.
trait T {
// The class using the trait must extend 'C'
require extends C;
// TODO: uncomment the next line to fix the error
require implements I;
public function do_stuff(): void {
$this->bar(); // We can access bar because we used "require extends"
$this->foo();
}
}
// Congratulations! You are done!
次回やりたいこと
1. WordPressを移行してみる
2. Hackで書き直す
3. ベンチマークを取って比較する
アップデート出来なくなるのでコピーで作業します (;´Д`)
ご清聴ありがとうございました

More Related Content

What's hot (20)

Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
Tanner Moushey ❖ Mission Lab - WordPress Agency
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
Eyal Vardi
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
Wildan Maulana
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
Dongho Cho
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
Eyal Vardi
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
Brian Swartzfager
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
Eyal Vardi
 
JavaScript patterns
JavaScript patternsJavaScript patterns
JavaScript patterns
Norihito YAMAKAWA
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Tsuyoshi Yamamoto
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi
 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
jeresig
 
Why You Shouldn't Write OO
Why You Shouldn't Write OO Why You Shouldn't Write OO
Why You Shouldn't Write OO
Yehuda Katz
 
Postman On Steroids
Postman On SteroidsPostman On Steroids
Postman On Steroids
Sara Tornincasa
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
Kazuchika Sekiya
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
Alexe Bogdan
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
Odoo
 
Let's Build A Gutenberg Block | WordCamp Europe 2018
Let's Build A Gutenberg Block | WordCamp Europe 2018Let's Build A Gutenberg Block | WordCamp Europe 2018
Let's Build A Gutenberg Block | WordCamp Europe 2018
Lara Schenck
 
Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8
Théodore Biadala
 
Drupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in DrupalDrupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in Drupal
Bryan Braun
 
Cервер на Go для мобильной стратегии
Cервер на Go для мобильной стратегииCервер на Go для мобильной стратегии
Cервер на Go для мобильной стратегии
Artem Kovardin
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
Eyal Vardi
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
Dongho Cho
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
Eyal Vardi
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
Brian Swartzfager
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
Eyal Vardi
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Tsuyoshi Yamamoto
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi
 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
jeresig
 
Why You Shouldn't Write OO
Why You Shouldn't Write OO Why You Shouldn't Write OO
Why You Shouldn't Write OO
Yehuda Katz
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
Kazuchika Sekiya
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
Alexe Bogdan
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
Odoo
 
Let's Build A Gutenberg Block | WordCamp Europe 2018
Let's Build A Gutenberg Block | WordCamp Europe 2018Let's Build A Gutenberg Block | WordCamp Europe 2018
Let's Build A Gutenberg Block | WordCamp Europe 2018
Lara Schenck
 
Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8
Théodore Biadala
 
Drupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in DrupalDrupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in Drupal
Bryan Braun
 
Cервер на Go для мобильной стратегии
Cервер на Go для мобильной стратегииCервер на Go для мобильной стратегии
Cервер на Go для мобильной стратегии
Artem Kovardin
 

Similar to Hack tutorial (20)

PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
Lars Jankowfsky
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
Marcello Duarte
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
Jace Ju
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
Stephan Schmidt
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
Wildan Maulana
 
PHP pod mikroskopom
PHP pod mikroskopomPHP pod mikroskopom
PHP pod mikroskopom
Saša Stamenković
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
 
PHP variables
PHP  variablesPHP  variables
PHP variables
Siddique Ibrahim
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
Raju Mazumder
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
jsmith92
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
AbhishekSharma2958
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
Federico Damián Lozada Mosto
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
Richard Paul
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
Eric Poe
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
Jace Ju
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
Stephan Schmidt
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
Wildan Maulana
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
Nikita Popov
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
jsmith92
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
Richard Paul
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
Eric Poe
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 

More from Wakana Yoshizawa (8)

情熱の入社オンボーディ ング~コスト下げる~
情熱の入社オンボーディ ング~コスト下げる~情熱の入社オンボーディ ング~コスト下げる~
情熱の入社オンボーディ ング~コスト下げる~
Wakana Yoshizawa
 
妊娠子育て中にReact js動画コースをudemyで公開するまで
妊娠子育て中にReact js動画コースをudemyで公開するまで妊娠子育て中にReact js動画コースをudemyで公開するまで
妊娠子育て中にReact js動画コースをudemyで公開するまで
Wakana Yoshizawa
 
Braintree+facebook messangerでチケット購入
Braintree+facebook messangerでチケット購入Braintree+facebook messangerでチケット購入
Braintree+facebook messangerでチケット購入
Wakana Yoshizawa
 
Djangoを使って爆速でapi作成した
Djangoを使って爆速でapi作成したDjangoを使って爆速でapi作成した
Djangoを使って爆速でapi作成した
Wakana Yoshizawa
 
開発前にインタビューをして分かったこと 吉澤和香奈
開発前にインタビューをして分かったこと 吉澤和香奈開発前にインタビューをして分かったこと 吉澤和香奈
開発前にインタビューをして分かったこと 吉澤和香奈
Wakana Yoshizawa
 
Webサーバー監視tips 吉澤和香奈
Webサーバー監視tips 吉澤和香奈Webサーバー監視tips 吉澤和香奈
Webサーバー監視tips 吉澤和香奈
Wakana Yoshizawa
 
前期反省&下期目標 吉澤和香奈
前期反省&下期目標 吉澤和香奈前期反省&下期目標 吉澤和香奈
前期反省&下期目標 吉澤和香奈
Wakana Yoshizawa
 
自己紹介&自社紹介 吉澤和香奈
自己紹介&自社紹介 吉澤和香奈自己紹介&自社紹介 吉澤和香奈
自己紹介&自社紹介 吉澤和香奈
Wakana Yoshizawa
 
情熱の入社オンボーディ ング~コスト下げる~
情熱の入社オンボーディ ング~コスト下げる~情熱の入社オンボーディ ング~コスト下げる~
情熱の入社オンボーディ ング~コスト下げる~
Wakana Yoshizawa
 
妊娠子育て中にReact js動画コースをudemyで公開するまで
妊娠子育て中にReact js動画コースをudemyで公開するまで妊娠子育て中にReact js動画コースをudemyで公開するまで
妊娠子育て中にReact js動画コースをudemyで公開するまで
Wakana Yoshizawa
 
Braintree+facebook messangerでチケット購入
Braintree+facebook messangerでチケット購入Braintree+facebook messangerでチケット購入
Braintree+facebook messangerでチケット購入
Wakana Yoshizawa
 
Djangoを使って爆速でapi作成した
Djangoを使って爆速でapi作成したDjangoを使って爆速でapi作成した
Djangoを使って爆速でapi作成した
Wakana Yoshizawa
 
開発前にインタビューをして分かったこと 吉澤和香奈
開発前にインタビューをして分かったこと 吉澤和香奈開発前にインタビューをして分かったこと 吉澤和香奈
開発前にインタビューをして分かったこと 吉澤和香奈
Wakana Yoshizawa
 
Webサーバー監視tips 吉澤和香奈
Webサーバー監視tips 吉澤和香奈Webサーバー監視tips 吉澤和香奈
Webサーバー監視tips 吉澤和香奈
Wakana Yoshizawa
 
前期反省&下期目標 吉澤和香奈
前期反省&下期目標 吉澤和香奈前期反省&下期目標 吉澤和香奈
前期反省&下期目標 吉澤和香奈
Wakana Yoshizawa
 
自己紹介&自社紹介 吉澤和香奈
自己紹介&自社紹介 吉澤和香奈自己紹介&自社紹介 吉澤和香奈
自己紹介&自社紹介 吉澤和香奈
Wakana Yoshizawa
 

Recently uploaded (20)

Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaPruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
OmarAlfredoDelCastil
 
Air Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdfAir Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Highway Engineering - Pavement materials
Highway Engineering - Pavement materialsHighway Engineering - Pavement materials
Highway Engineering - Pavement materials
AmrutaBhosale9
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
All about the Snail Power Catalog Product 2025
All about the Snail Power Catalog  Product 2025All about the Snail Power Catalog  Product 2025
All about the Snail Power Catalog Product 2025
kstgroupvn
 
HVAC Air Filter Equipment-Catalouge-Final.pdf
HVAC Air Filter Equipment-Catalouge-Final.pdfHVAC Air Filter Equipment-Catalouge-Final.pdf
HVAC Air Filter Equipment-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
하이플럭스 / HIFLUX Co., Ltd.
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete ColumnsAxial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Journal of Soft Computing in Civil Engineering
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
Proposed EPA Municipal Waste Combustor Rule
Proposed EPA Municipal Waste Combustor RuleProposed EPA Municipal Waste Combustor Rule
Proposed EPA Municipal Waste Combustor Rule
AlvaroLinero2
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
Software Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha TasnuvaSoftware Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha Tasnuva
tanishatasnuva76
 
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDINGMODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaPruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
OmarAlfredoDelCastil
 
Highway Engineering - Pavement materials
Highway Engineering - Pavement materialsHighway Engineering - Pavement materials
Highway Engineering - Pavement materials
AmrutaBhosale9
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
All about the Snail Power Catalog Product 2025
All about the Snail Power Catalog  Product 2025All about the Snail Power Catalog  Product 2025
All about the Snail Power Catalog Product 2025
kstgroupvn
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
Proposed EPA Municipal Waste Combustor Rule
Proposed EPA Municipal Waste Combustor RuleProposed EPA Municipal Waste Combustor Rule
Proposed EPA Municipal Waste Combustor Rule
AlvaroLinero2
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
Software Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha TasnuvaSoftware Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha Tasnuva
tanishatasnuva76
 
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDINGMODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 

Hack tutorial

  • 2. 自己紹介 ↳ 吉澤和香奈 ↳ カツラじゃありません ↳ 1987/6/30生まれO型 ↳ PHPに出会ったのは2012 年の夏です ↳ HNは「wakana」「わかな だょ〜」「ブ〜バ〜」等、気 分により多数あります
  • 14. /***************************************************/ /****************** Hack Tutorial ******************/ /***************************************************/ /************ Click 'Next' to get started! *********/
  • 16. <?php // ^-- FIXME: replace <?php with <?hh // A Hack file always starts with <?hh
  • 17. <?hh // ^-- FIXME: replace <?php with <?hh // A Hack file always starts with <?hh
  • 19. <?hh // Hack functions are annotated with types. function my_negation(bool $x): bool { return !$x; } // FIXME: annotate this function parameter // and return with the type 'int'. function add_one(/* TODO */ $x): /* TODO */ { return $x+1; }
  • 20. <?hh // Hack functions are annotated with types. function my_negation(bool $x): bool { return !$x; } // FIXME: annotate this function parameter // and return with the type 'int'. function add_one(int $x): int { return $x+1; }
  • 22. <?hh /* Hack errors come in multiple parts. * Hover over the underlined parts! */ function add_one(int $x): int { return $x+1; } function test(): void { $my_string = 'hello'; // Some clever code ... add_one($my_string); }
  • 23. <?hh /* Hack errors come in multiple parts. * Hover over the underlined parts! */ function add_one(int $x): int { return $x+1; } function test(): void { $my_string = 'hello'; // Some clever code ... add_one((int) $my_string); }
  • 25. <?hh // Prefixing a type with '?' permits null. // TODO: fix the type of the parameter $x to permit null. function f(int $x): void { var_dump($x); } function test(): void { f(123); f(null); }
  • 26. <?hh // Prefixing a type with '?' permits null. // TODO: fix the type of the parameter $x to permit null. function f(?int $x): void { var_dump($x); } function test(): void { f(123); f(null); }
  • 28. <?hh interface User { public function getName(): string; } function get_user_name(?User $user): string { if($user !== null) { // We checked that $user was not null. // Its type is now 'User'. /* TODO: return $user->getName() */ } return '<invalid name>'; } function test(User $user) { $name1 = get_user_name($user); $name2 = get_user_name(null); }
  • 29. <?hh interface User { public function getName(): string; } function get_user_name(?User $user): string { if($user !== null) { // We checked that $user was not null. // Its type is now 'User'. return $user->getName(); } return '<invalid name>'; } function test(User $user) { $name1 = get_user_name($user); $name2 = get_user_name(null); }
  • 31. <?hh interface User { public function getName(): string; } // There are many ways to handle null values. // Throwing an exception is one of them. function get_user_name(?User $user): string { if($user === null) { throw new RuntimeException('Invalid user name'); } /* TODO: return $user->getName() */ } function test(User $user) { $name1 = get_user_name($user); $name2 = get_user_name(null); }
  • 32. <?hh interface User { public function getName(): string; } // There are many ways to handle null values. // Throwing an exception is one of them. function get_user_name(?User $user): string { if($user === null) { throw new RuntimeException('Invalid user name'); } return $user->getName(); } function test(User $user) { $name1 = get_user_name($user); $name2 = get_user_name(null); }
  • 34. <?hh // Hack introduces new collection types (Vector, Set and Map). function test(): int { // Vector is preferred over array(1, 2, 3) $vector = Vector {1, 2, 3}; $sum = 0; foreach ($vector as $val) { $sum += $val; } return $sum; }
  • 35. <?hh // Hack introduces new collection types (Vector, Set and Map). function test(): int { // Vector is preferred over array(1, 2, 3) $vector = Vector {1, 2, 3}; $sum = 0; foreach ($vector as $val) { $sum += $val; } return $sum; } // Arrayよりも高速なVectorが使えます
  • 37. <?hh // Hack uses generics for Collection types. // TODO: fix the return type of the function 'test' function test(): Vector<string> { $vector = Vector {1, 2, 3}; return $vector; }
  • 38. <?hh // Hack uses generics for Collection types. // TODO: fix the return type of the function 'test' function test(): Vector<string> { $vector = Vector {“1”, “2”, “3”}; return $vector; }
  • 40. <?hh function vector_add1(Vector<int> $v): Vector<int> { // Example of lambda expressions. return $v->map($x ==> $x + 1); } function vector_mult2(Vector<int> $v): Vector<int> { // TODO: write a function multiplying all the elements by 2 }
  • 41. <?hh function vector_add1(Vector<int> $v): Vector<int> { // Example of lambda expressions. return $v->map($x ==> $x + 1); } function vector_mult2(Vector<int> $v): Vector<int> { // TODO: write a function multiplying all the elements by 2 return $v->map($x ==> $x * 2); }
  • 43. /* * Congratulations! * You completed the beginner's tutorial. * * Click next to continue in expert mode. */
  • 45. <?hh // All the members of a class must be initialized class Point { private float $x; private float $y; public function __construct(float $x, float $y) { $this->x = $x; // FIXME: initalize the member 'y' } }
  • 46. <?hh // All the members of a class must be initialized class Point { private float $x; private float $y; public function __construct(float $x, float $y) { $this->x = $x; // FIXME: initalize the member 'y' $this->y = $y; } }
  • 48. <?hh // Check out this new syntax! // It's shorter and does the same thing ... class Point { public function __construct( private float $x, private float $y ) {} }
  • 49. <?hh // Check out this new syntax! // It's shorter and does the same thing ... class Point { public function __construct( private float $x, private float $y ) {} } // このような新しい書き方で今までより短くなります
  • 51. <?hh // You can create your own generics! class Store<T> { public function __construct(private T $data) {} public function get(): T { return $this->data; } public function set(T $x): void { $this->data = $x; } } // TODO: fix the return type of the function test function test(): Store<int> { $data = 'Hello world!'; $x = new Store($data); return $x; }
  • 52. <?hh // You can create your own generics! class Store<T> { public function __construct(private T $data) {} public function get(): T { return $this->data; } public function set(T $x): void { $this->data = $x; } } // TODO: fix the return type of the function test function test(): Store<string> { $data = 'Hello world!'; $x = new Store($data); return $x; }
  • 54. <?hh // You can specify constraints on generics. interface MyInterface { public function foo(): void; } // TODO: uncomment 'as MyInterface' // T as MyInterface means any object as long as // it implements MyInterface function call_foo<T /* as MyInterface */>(T $x): T { $x->foo(); return $x; }
  • 55. <?hh // You can specify constraints on generics. interface MyInterface { public function foo(): void; } // TODO: uncomment 'as MyInterface' // T as MyInterface means any object as long as // it implements MyInterface function call_foo<T as MyInterface>(T $x): T { $x->foo(); return $x; }
  • 57. <?hh // The type 'this' always points to the most derived type class MyBaseClass { protected int $count = 0; // TODO: replace 'MyBaseClass' by 'this' public function add1(): MyBaseClass { $this->count += 1; return $this; } } class MyDerivedClass extends MyBaseClass { public function print_count(): void { echo $this->count; } } function test(): void { $x = new MyDerivedClass(); $x->add1()->print_count(); }
  • 58. <?hh // The type 'this' always points to the most derived type class MyBaseClass { protected int $count = 0; // TODO: replace 'MyBaseClass' by 'this' public function add1(): this { $this->count += 1; return $this; } } class MyDerivedClass extends MyBaseClass { public function print_count(): void { echo $this->count; } } function test(): void { $x = new MyDerivedClass(); $x->add1()->print_count(); }
  • 60. <?hh // When a type is too long, you can use a type alias. type Matrix<T> = Vector<Vector<T>>; function first_row<T>(Matrix<T> $matrix): Vector<T> { return $matrix[0]; }
  • 61. <?hh // When a type is too long, you can use a type alias. type Matrix<T> = Vector<Vector<T>>; function first_row<T>(Matrix<T> $matrix): Vector<T> { return $matrix[0]; } // タイプが長い時は別名を指定出来ます
  • 63. <?hh // Tuples represent fixed size arrays. // TODO: fix the return type. function my_first_pair((int, bool) $pair): int { list($_, $result) = $pair; return $result; }
  • 64. <?hh // Tuples represent fixed size arrays. // TODO: fix the return type. function my_first_pair((int, bool) $pair): int { list($result, $_) = $pair; return $result; }
  • 66. <?hh // Shapes can be used for arrays with constant string keys. type my_shape = shape( 'field1' => int, 'field2' => bool, ); function first_shape(): my_shape { $result = shape('field1' => 1); // TODO: set 'field2' to the value true // on $result to complete the shape. return $result; }
  • 67. <?hh // Shapes can be used for arrays with constant string keys. type my_shape = shape( 'field1' => int, 'field2' => bool, ); function first_shape(): my_shape { $result = my_shape(1, true); // TODO: set 'field2' to the value true // on $result to complete the shape. return $result; }
  • 69. <?hh // You can specify the types of functions too. function apply_int<T>((function(int): T) $callback, int $value): T { // TODO: return $callback($value) }
  • 70. <?hh // You can specify the types of functions too. function apply_int<T>((function(int): T) $callback, int $value): T { return $callback($value); }
  • 72. <?hh // XHP is useful to build html (or xml) elements. // The escaping is done automatically, it is important to avoid // security issues (XSS attacks). function build_paragraph(string $text, string $style): :div { return <div style={$style}> <p>{$text}</p> </div>; }
  • 73. <?hh // XHP is useful to build html (or xml) elements. // The escaping is done automatically, it is important to avoid // security issues (XSS attacks). function build_paragraph(string $text, string $style): :div { return <div style={$style}> <p>{$text}</p> </div>; } // XHP記法でHTMLまたはXMLを構築することにより、クロスサイトスクリプティング対 策が実現できます
  • 75. <?hh /* Opaque types let you hide the representation of a type. * * The definition below introduces the new type 'user_id' * that will only be compatible with 'int' within this file. * Outside of this file, 'user_id' becomes "opaque"; it won't * be compatible with 'int' anymore. */ newtype user_id = int; function make_user_id(int $x): user_id { // Do some checks ... return $x; } // You should only use this function for rendering function user_id_to_int(user_id $x): int { return $x; }
  • 76. <?hh /* Opaque types let you hide the representation of a type. * * The definition below introduces the new type 'user_id' * that will only be compatible with 'int' within this file. * Outside of this file, 'user_id' becomes "opaque"; it won't * be compatible with 'int' anymore. */ newtype user_id = int; function make_user_id(int $x): user_id { // Do some checks ... return $x; } // You should only use this function for rendering function user_id_to_int(user_id $x): int { return $x; } // user_idタイプを作る事により、このファイルで型を管理し、他のファイルではuser_id型になります
  • 78. <?hh class MyBaseClass { // TODO: fix the typo in the name of the method. public function get_uuser(): MyUser { return new MyUser(); } } class MyDerivedClass extends MyBaseClass { /* <<Override>> is used to specify that get_user has been inherited. * When that's not the case, Hack gives an error. */ <<Override>> public function get_user(): MyUser { return new MyUser(); } }
  • 79. <?hh class MyBaseClass { // TODO: fix the typo in the name of the method. public function get_user(): MyUser { return new MyUser(); } } class MyDerivedClass extends MyBaseClass { /* <<Override>> is used to specify that get_user has been inherited. * When that's not the case, Hack gives an error. */ <<Override>> public function get_user(): MyUser { return new MyUser(); } }
  • 81. <?hh class C { protected function bar(): void {} } interface I { public function foo(): void; } // 'require' lets you specify what the trait needs to work properly. trait T { // The class using the trait must extend 'C' require extends C; // TODO: uncomment the next line to fix the error // require implements I; public function do_stuff(): void { $this->bar(); // We can access bar because we used "require extends" $this->foo(); } }
  • 82. <?hh class C { protected function bar(): void {} } interface I { public function foo(): void; } // 'require' lets you specify what the trait needs to work properly. trait T { // The class using the trait must extend 'C' require extends C; // TODO: uncomment the next line to fix the error require implements I; public function do_stuff(): void { $this->bar(); // We can access bar because we used "require extends" $this->foo(); } }
  • 84. 次回やりたいこと 1. WordPressを移行してみる 2. Hackで書き直す 3. ベンチマークを取って比較する アップデート出来なくなるのでコピーで作業します (;´Д`)