SlideShare a Scribd company logo
Typed Drupal - A great combination of Drupal 8 and PHP 7
JoinusforSprints
First-Time Sprinter Workshop - 9am-12pm in Room 271-273
Mentored Core Sprint - 9am-6pm in Room 275-277
General Sprints - 9am-6pm in Room 278-282
Friday, May 13 at the Convention Center
TypedDrupal-AgreatcombinationofD8and
PHP7
Aditya Ghan
AdityaGhan(Adi)
SolutionArchitect
aditya.ghan@blisstering.com
@AdityaGhan
Agenda
✤ Typing as a concept
✤ Categories of Type Systems
✤ Type Hinting in PHP
✤ Non Scalar Type Hinting
✤ Type Juggling.
Agenda
✤ Scalar Type Hinting in PHP7
✤ Return Type Declarations in PHP7
✤ Type Checking Modes
✤ Handling Type Exceptions
✤ D8 and PHP7
Typingasaconcept
Typingasaconcept
Giving data types to
❖ Variable Declarations
❖ Parameters of a function
❖ Return value of a function
❖ Expressions
CategoriesofTypeSystems
TypeSystems- Categories
✤ Strong (Java, Python)
✤ Weak (PHP, Perl)
✤ Static (C#, Java)
✤ Dynamic (PHP, Python)
Categories(TypeSystems)
Strongly Typed language
Strongly typed language is more likely to generate an error or refuse to
compile if type checking fails.
A Weakly typed language may produce unpredictable results or may
perform implicit type conversion in case of type conflict.
Weakly Typed Language
Typing-Categories
Statically Typed language
A statically typed language checks the type system at compile time.
A dynamically typed language interprets the type of a variable at runtime
Dynamically Typed Language
Strong
Static Dynamic
Weak
TypeHintinginPHP
TypeHintinginPHP
Type Hinting allows you to specify the type of
data which a method is expecting.
Parameter type which the method is expecting
PHP 5.x
NonScalarTypeHinting
NonScalarTypeHinting
Type hinting for complex data types.
Objects (Since PHP 5.0), Array (Since PHP 5.1),
Callable (Since PHP 5.4)
Output: Array([0]=>1[1]=>2)
PHP 5.x
PHPCatchable fatalerror: Argument1passedto
adi_function()mustbeaninstanceofint,integergiven
PHP 5.x
TypeJuggling
TypeJuggling
Type Juggling is a feature (or design
flaw, according to where you stand on
typing) where we convert a variable
type to the most appropriate type
according to the action performed. It
can lead to an unexpected output.
Output: FirstislessthanSecond
PHP 5.x
Output: SecondislessthanFirst
PHP 5.x
PHP 5.x
Output: Pleasepassintegerinputs
EnterPHP7!
ScalarTypeHintinginPHP7
ScalarTypeHintinginPHP7
RFC introduced last year:
https://wiki.php.net/rfc/scalar_type_hints_v5
Extends type hints for scalar types.
Scalar Types – integer, float, string and boolean
Output: 1
PHP 7
PHPCatchable fatalerror: Argument1passedto
adi_function()mustbeaninstanceofint,integergiven
PHP 5.x
Output: UncaughtTypeError:Argument1passedto
adi_function()mustbeofthetypeinteger,stringgiven
PHP 7
Output: UncaughtTypeError:Argument2passedto
compare_function()mustbeofthetypeinteger,stringgiven
PHP 7
ScalarTypeHinting-Benefits
Benefits:
✤ Less Bugs (Especially the ones
which are Hard to debug)
✤ Code Readability
✤ Concrete function definition.
ReturnTypeDeclarationsinPHP7
ReturnTypeDeclarations
In PHP7, we could specify the data type of the return value
of a function. This is great!
Adding Return Type Declarations facilitates a nice contract
where the caller is sure that the called function would return
a value with type as promised
Output: 1
ReturnTypeDeclaration
PHP 7
Output: Returnvalueofadi_function()mustbeofthetype
integer,stringreturned
PHP 7
ReturnTypeDeclarationfeatures:
✤ Contract between caller and callable function.
✤ No error handling required in the caller function.
✤ Function definitions are more readable.
AndFinally!!
NoMoreisset’sand!empty’s!
TypeCheckingModes
WeakMode
Weak Mode checks the parameter
types and return types in a weak
fashion for a file. It will perform Type
juggling for matching the type of the
parameter to the passed value.
Output: 1
PHP 7
Output: UncaughtTypeError:Argument1passedto
adi_function()mustbeofthetypeinteger,stringgiven
PHP 7
StrictMode
Strict Mode checks the parameter
types and return types in a strict
fashion for a file.
Output: UncaughtTypeError:Argument1passedto
adi_function()mustbeofthetypeinteger,stringgiven
PHP 7
Output: 1
PHP 7
Importantpointstonote:
✤ Return Type Declarations are optional, even in the
strict mode.
✤ The only type conversion allowed is int to float, i:e
Float parameter type can accept a integer value.
✤ NULL is still allowed as a default value for a
function parameter.
Output: 10
PHP 7
Rememberthis?WhiteScreenofDeath(WSOD)PHP7EngineExceptionsarehappytohelp!
HandlingTypeExceptions
PHP 7
Output: Bro,Somethingwentwrong,pleasepassproperinputs
“Hey, What about Drupal? Isn’t this Drupalcon? ”
~ Abraham Lincoln
Typed Drupal - A great combination of Drupal 8 and PHP 7
Drupal8andPHP7
Drupal 8 has a 100% pass on PHP7.
https://www.drupal.org/node/3060/qa
Let’sseea“Typed”D8module
DrupalconNewOrleans
drupalcon-new-orleans
Sluggify!
AnyQuestions?
ForModuleCode:
https://github.com/aghan/typed_drupal
SoHowWasIt?-TellUsWhatYouThink
Evaluate this session -
https://events.drupal.org/neworleans2016/schedule/2016-05-10
AdityaGhan–aditya.ghan@blisstering.com
AdityaGhan(Adi)
Email:aditya.ghan@blisstering.com
Twitter:@AdityaGhan
Thankyou!

More Related Content

PDF
Designing Test Cases for the Gilded Rose Kata v2 (2015)
PDF
Coding Dojo: Bank OCR Outside-In (2015)
PDF
Deliberate Practice, New Learning Styles (2015)
PDF
Extract Method Refactoring Workshop (2016)
PDF
Typed Drupal - A great combination of Drupal 8 and PHP7
PDF
TDD as if You Meant It (2013)
PDF
Idiomatic R for Rosetta Code (2013)
PPTX
Functional Programming in JavaScript & ESNext
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Coding Dojo: Bank OCR Outside-In (2015)
Deliberate Practice, New Learning Styles (2015)
Extract Method Refactoring Workshop (2016)
Typed Drupal - A great combination of Drupal 8 and PHP7
TDD as if You Meant It (2013)
Idiomatic R for Rosetta Code (2013)
Functional Programming in JavaScript & ESNext

What's hot (20)

PDF
Coding Dojo: Mars Rover (2014)
PDF
Coding Dojo: Functional Calisthenics (2016)
PDF
Outside-in Test Driven Development - the London School of TDD
PDF
Coding Dojo: Naming with Dices (2021)
PDF
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
PDF
Coding Dojo: Baby Steps Push Challenge (2021)
PDF
Designing Test Cases for the Gilded Rose Kata (2013)
PDF
Writing Tests with the Unity Test Framework
PDF
Deliberate Practice (Agile Slovenia 2015)
PDF
Clean Readable Specifications (ETC 2016)
PDF
Code Reviews in Python - PyZh
PDF
The Brutal Refactoring Game (2013)
PDF
Static analysis for perl
PDF
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
ODP
PDF
Grooming with Groovy
PDF
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
PDF
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
PDF
Performance profiling and testing of symfony application 2
PDF
Refactoring the Tennis Kata v2 (2016)
Coding Dojo: Mars Rover (2014)
Coding Dojo: Functional Calisthenics (2016)
Outside-in Test Driven Development - the London School of TDD
Coding Dojo: Naming with Dices (2021)
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Coding Dojo: Baby Steps Push Challenge (2021)
Designing Test Cases for the Gilded Rose Kata (2013)
Writing Tests with the Unity Test Framework
Deliberate Practice (Agile Slovenia 2015)
Clean Readable Specifications (ETC 2016)
Code Reviews in Python - PyZh
The Brutal Refactoring Game (2013)
Static analysis for perl
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
Grooming with Groovy
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
Performance profiling and testing of symfony application 2
Refactoring the Tennis Kata v2 (2016)
Ad

Similar to Typed Drupal - A great combination of Drupal 8 and PHP 7 (20)

PDF
PHP7 is coming
PPTX
Strong typing : adoption, adaptation and organisation
PDF
PHP7 - Scalar Type Hints & Return Types
PDF
Strong typing @ php leeds
PPTX
Php 7 - YNS
PPTX
Why choose Hack/HHVM over PHP7
PDF
What To Expect From PHP7
PDF
Unknown features of PHP
PDF
TAKING PHP SERIOUSLY - Keith Adams
PPTX
PHP 7 Crash Course - php[world] 2015
PDF
PHP7: Hello World!
PDF
Php 7 crash course
PPTX
PHP 7 Crash Course
PDF
Start using PHP 7
PDF
50 shades of PHP
PPTX
Learning php 7
PDF
What's new in PHP 7.1
PPTX
Peek at PHP 7
PDF
PHP7.1 New Features & Performance
PPT
Php5 vs php7
PHP7 is coming
Strong typing : adoption, adaptation and organisation
PHP7 - Scalar Type Hints & Return Types
Strong typing @ php leeds
Php 7 - YNS
Why choose Hack/HHVM over PHP7
What To Expect From PHP7
Unknown features of PHP
TAKING PHP SERIOUSLY - Keith Adams
PHP 7 Crash Course - php[world] 2015
PHP7: Hello World!
Php 7 crash course
PHP 7 Crash Course
Start using PHP 7
50 shades of PHP
Learning php 7
What's new in PHP 7.1
Peek at PHP 7
PHP7.1 New Features & Performance
Php5 vs php7
Ad

Recently uploaded (20)

PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
top salesforce developer skills in 2025.pdf
PPTX
Introduction to Artificial Intelligence
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Nekopoi APK 2025 free lastest update
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
AI in Product Development-omnex systems
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 41
How Creative Agencies Leverage Project Management Software.pdf
top salesforce developer skills in 2025.pdf
Introduction to Artificial Intelligence
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Choose the Right IT Partner for Your Business in Malaysia
Nekopoi APK 2025 free lastest update
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Reimagine Home Health with the Power of Agentic AI​
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms I-SECS-1021-03
VVF-Customer-Presentation2025-Ver1.9.pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Odoo POS Development Services by CandidRoot Solutions
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Softaken Excel to vCard Converter Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
AI in Product Development-omnex systems

Typed Drupal - A great combination of Drupal 8 and PHP 7