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

What's hot (20)

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

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

PDF
PHP7 is coming
julien pauli
 
PPTX
Strong typing : adoption, adaptation and organisation
Damien Seguy
 
PDF
PHP7 - Scalar Type Hints & Return Types
Eric Poe
 
PDF
Strong typing @ php leeds
Damien Seguy
 
PPTX
Php 7 - YNS
Alex Amistad
 
PPTX
Why choose Hack/HHVM over PHP7
Yuji Otani
 
PDF
What To Expect From PHP7
Codemotion
 
PDF
Unknown features of PHP
squid_zce
 
PDF
TAKING PHP SERIOUSLY - Keith Adams
Hermes Alves
 
PPTX
PHP 7 Crash Course - php[world] 2015
Colin O'Dell
 
PDF
PHP7: Hello World!
Pavel Nikolov
 
PDF
Php 7 crash course
Khaireddine Hamdi
 
PPTX
PHP 7 Crash Course
Colin O'Dell
 
PDF
Start using PHP 7
Oscar Merida
 
PDF
50 shades of PHP
Maksym Hopei
 
PPTX
Learning php 7
Ed Lomonaco
 
PDF
What's new in PHP 7.1
Simon Jones
 
PPTX
Peek at PHP 7
John Coggeshall
 
PDF
PHP7.1 New Features & Performance
Xinchen Hui
 
PPT
Php5 vs php7
gentlex2
 
PHP7 is coming
julien pauli
 
Strong typing : adoption, adaptation and organisation
Damien Seguy
 
PHP7 - Scalar Type Hints & Return Types
Eric Poe
 
Strong typing @ php leeds
Damien Seguy
 
Php 7 - YNS
Alex Amistad
 
Why choose Hack/HHVM over PHP7
Yuji Otani
 
What To Expect From PHP7
Codemotion
 
Unknown features of PHP
squid_zce
 
TAKING PHP SERIOUSLY - Keith Adams
Hermes Alves
 
PHP 7 Crash Course - php[world] 2015
Colin O'Dell
 
PHP7: Hello World!
Pavel Nikolov
 
Php 7 crash course
Khaireddine Hamdi
 
PHP 7 Crash Course
Colin O'Dell
 
Start using PHP 7
Oscar Merida
 
50 shades of PHP
Maksym Hopei
 
Learning php 7
Ed Lomonaco
 
What's new in PHP 7.1
Simon Jones
 
Peek at PHP 7
John Coggeshall
 
PHP7.1 New Features & Performance
Xinchen Hui
 
Php5 vs php7
gentlex2
 
Ad

Recently uploaded (20)

PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Ad

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