SlideShare a Scribd company logo
1 of 80
PHP EXTENSIONS
Making the language even better
Congratulations!
• You’ve decided to learn “down the stack”
• You’ll learn more than you do “across the stack”
• Your brain will hurt a bit
• This will require you to be involved in your own
learning process
• It is HARD WORK to be good at anything new
WARNING!
The things shown here to apply to PHP 7 only!
Why do extensions?
• Talk to a C or C++ library
• Modify the way the engine works (zend extensions
usually)
• Make slow parts of code run faster
But I want to
change the
engine!
Baby steps, baby steps
Wrapper
Extension
Speed and/or
Algorithm
Extension
Zend
Extension
SAPI
Engine - Lexer,
AST, Parser
But I don’t know C!
1. compiled
2. strictly typed
3. php internals do “hard” stuff
4. copy and paste! boilerplate and macros
5. cairo, pecl_http, date
6. Don’t do the hard stuff first!
lxr.php.net
https://php-lxr.adamharvey.name/source/
But I want to learn C
Also try:
• http://www.learn-c.org/
• http://c.learncodethehardway.org/book/
• http://aelinik.free.fr/c/
Practice Practice Practice!
Preparing to
Compile
The big list
Quick Setup Needs
1. compiler
2. sdk
3. tools
4. dependencies
5. code
phpize is your friend!
How to Compile an Extension
1. phpize
2. ./configure
3. make
4. make install
5. make test
configure might require –with-php-config=/path/to/something
but…
But wait – there’s more!
• Compile your own PHP source, use a –prefix
 /usr/local/php-7.0-debug-zts is one I use
 I also have 20 php’s installed 
• We want developer specific flags
 --enable-maintainer-zts and --enable-debug
 optionally –enable-gcov
• install gdb and valgrind and optionally lcov
• this is easy on Ubuntu and similar systems where
packages are easy to get
• You can also compile php with clang instead of gcc
and do things like use static analysis
Rasmus to the Rescue!
• https://github.com/rlerdorf/php7dev/blob/master/README.md
tl;dr
1. install virtualbox
2. install vagrant
3. git clone https://github.com/rlerdorf/php7dev.git
4. cd php7dev
5. vagrant up
6. vagrant ssh
7. makephp 7
How to Play along
git clone https://github.com/auroraeosrose/php-extensions-
code.git
git clone git://github.com/auroraeosrose/php-
extensions-code.git
git checkout scaffolding
phpize
./configure
make
make test
Let’s write an
extension!
But wait – there’s more….
1. Set up compile environment
2. Write a module definition
3. Learn about the PHP lifecycle
4. Learn about zvals
5. Add functions
6. ???
7. Profit!
Every Other Extensions Talk
DOIN IT RONG
Which do YOU want?
1. Do something you can’t do in userland
2. Utilize a C library
3. Make slow code faster
Maybe you should just use ffi!
Step 1. Why?
What is FFI?
• Foreign function interface
• Java calls it JNI
• HHVM calls it HNI
• Python calls it “ctypes” (do not ask, stupidest name
ever)
• C# calls it P/Invoke
• Ruby calls it FFI
• PHP calls it…
FFI
Oh wait…
• php’s ffi is rather broken (last release is 2004-01-20)
• php’s ffi has no maintainer (ilia and wez were doing
it)
• It needs some TLC
• There’s MFFI but it’s not done
 https://github.com/mgdm/MFFI
• Are you interested and not afraid? See me!
1. I hate parsing URIs
2. PHP’s parse_url is… not the best
3. How about an extension that wraps something
that parses uris in an excellent fashion
4. RESEARCH TIME
Step 2. What
Google says…
C library to the rescue!
• uriparser.sourceforge.net
• strictly RFC 3986 compliant
• available on many systems as packages
• cross platform
• documented
http://uriparser.sourceforge.net/doc/html/
1. Think about what the API should be
2. Look at the C APIs but don’t mimic them
3. Write an example of how you WANT it to work
4. Write more then one example!
5. Turn these examples into your first tests
6. Yes this is TDD
Step 3. How
1. This is copy and paste
1. config.m4 & config.w32
2. macros for version api changes if necessary
3. main module file (php_{$ext}.c)
4. main header file (php_{$ext}.h)
2. Compile it and test!
Step 6. Extension Scaffolding
Configure files
Module struct
Scaffolding rules
1. make sure you name your files in a standard way
2. document! use a license header, proto statements
3. read the coding standards
http://lxr.php.net/xref/PHP_5_6/CODING_STANDA
RDS
4. FOLLOW THE CODING STANDARDS
5. use version control early on – github is easy!
php –d extension=myext.so –m
The scaffold extension should show up in the list
Make sure to
1. define a version constant
2. read and use PHP code standards
Check if it works
1. run-test.php
2. make test will magically have output
more at http://qa.php.net/write-test.php and docs
at http://qa.php.net/phpt_details.php
Step 7. Write the test
PHPT tests
Let’s take a break here for
some semi-live demos…
Zval
The guts behind PHP’s type system
Typing systems compared
Static Typing (C)
• Variables must be declared
before use
• Variables must be given a
type at declaration
• “compile time” checking
Dynamic Typing (PHP)
• Variables don’t have to be
declared before use
• Variables can change types
• “run time” checking
zval
zval continued…
For more on the new zval
https://nikic.github.io/2015/05/05/Internal-value-representation-in-
PHP-7-part-1.html
long any numeric
double numeric with decimal
char* +
size_t
(length)
strings, binary
Hashtable dictionaries, arrays,structs
object any complicated type
For more on the new string type
http://jpauli.github.io/2015/09/18/php-string-management.html
How do I get C types from a ZVAL?
Z_LVAL(zval) Z_LVAL_P(zval_p) Z_LVAL_PP(zval_pp)
Z_BVAL(zval) Z_BVAL_P(zval_p) Z_BVAL_PP(zval_pp)
Z_DVAL(zval) Z_DVAL_P(zval_p) Z_DVAL_PP(zval_pp)
Z_STRVAL(zval) Z_STRVAL_P(zval_p) Z_STRVAL_PP(zval_pp)
Z_STRLEN(zval) Z_STRLEN_P(zval_p) Z_STRLEN_PP(zval_pp)
Z_ARRVAL(zval) Z_ARRVAL_P(zval_p) Z_ARRVAL_PP(zval_pp)
Z_OBJ(zval) Z_OBJ_P(zval_p) Z_OBJVAL_PP(zval_pp)
Z_OBJ_HANDLE(zv
al)
Z_OBJ_HANDLE_P(zval
_p)
Z_OBJ_HANDLE_PP(zval_
pp)
Z_OBJ_HT(zval) Z_OBJ_HT_P(zval_p) Z_OBJ_HT_PP(zval_pp)
Z_OBJCE(zval) Z_OBJCE_P(zval_p) Z_OBJCE_PP(zval_pp)
Z_OBJPROP(zval) Z_OBJPROP_P(zval_p) Z_OBJPROP_PP(zval_pp)
Z_TYPE(zval) Z_TYPE_P(zval_p) Z_TYPE_PP(zval_pp)
My extension
does nothing!
Back to our regularly schedule content
1. tell it to link to our C library
2. add a function
3. learn how to get data
4. learn how to return data
Step 8. Actually do something
I hate autotools…
• Also known as the gnu build system
• provider of much pain, but much good use as well
• autoconf – generates a configure script (we cheat
with phpize on shared extensions)
 makes a configure we run to set up our information,
mainly a config.h file
• automake – creates makefiles
• libtool – creates static and dynamic libraries
• Windows? Well php wrote it’s own version of
autotools – in jscript (windows javascript variant)
Anatomy of a Function
Wait – what was that?
• Define your function in C
 use a special call to parse parameters passed by the
user
 use a special zval to return data to the user
• Tell PHP your extension provides this function
 put it in your “giant struct of doom” that lists them all
 send it to php when in your module struct
• Tell PHP what arguments your extension provides
 If your argument information and zpp argue users will be
angry
 Yes it sucks you can’t just do one 
php type code
c type
array or object a zval *
boolean b zend_bool
class C zend_class_entry *
double d double
callable f zend_fcall_info andzend_fcall_info_cache
array or HASH_OF(object) H HashTable*
array h HashTable*
integer l zend_long
integer L zend_long with LONG_MAX, LONG_MIN
limits
object o zval *
object of specific type O zval *, zend_class_entry
string (no null bytes) p char*, size_t
resource r zval *
string (possible null bytes) s char*, size_t
actual zval z zval *
actual zval Z zval**
zend_parse_parameters
type code
variable args (any) * int, zval**
variable args (1 or more) + int, zval**
| anything after is optional, use defaults
/ use SEPARATE_ZVAL_IF_NOT_REF
doesn’t apply to b, l, and d ! C NULL for zval null
return_value
RETURN_RES(l)
RETURN_BOOL(b)
RETURN_NULL()
RETURN_LONG(l)
RETURN_DOUBLE(d)
RETURN_STRING(s)
RETURN_STRINGL(s, l)
RETURN_EMPTY_STRING()
RETURN_ZVAL(zv, copy, dtor)
RETURN_FALSE
RETURN_TRUE
RETVAL_RES(l)
RETVAL_BOOL(b)
RETVAL_NULL()
RETVAL_LONG(l)
RETVAL_DOUBLE(d)
RETVAL_STRING(s)
RETVAL_STRINGL(s, l)
RETVAL_EMPTY_STRING()
RETVAL_ZVAL(zv, copy, dtor)
RETVAL_FALSE
RETVAL_TRUE
Complex Data
array_init()
add_(index|assoc)_long()
add_(index|assoc)_bool()
add_(index|assoc)_string()
object_init()
add_property_long()
add_property_bool()
add_property_string()
Now to visit the attach-library
branch…
1. namespaces
2. classes
3. methods
4. constants
Step 9. Make it shiny
Classes
1. name, parent, and flags
2. hashtables of methods, default methods, static
methods
3. hashtables of static properties, default
properties, and properties
4. object handlers
5. union of either file information, or internal
structures (for internal classes)
add-basic-class branch
Lifecycle
Let’s take a moment to learn about how PHP works
internally
Lifecycle
PHP stops
MSHUTDOWN – for each extension
RSHUTDOWN – for each request
cleanup after test.php
RINIT – for each request
execute test.php
MINIT – for each extension
request/parse test.php
PHP starts
php test.php
Lifecycle Threaded
PHP stops
MSHUTDOWN – for each extension
request index.php request foo.php
RINIT – for each request
• execute test.php
RSHUTDOWN – for each request
• cleanup after test.php
RINIT – for each request
• execute test.php
RSHUTDOWN – for each request
• cleanup after test.php
MINIT – for each extension
apache starts
Class Properties
add-class-properties branch
Class Constants
add-class-constants branch
My class does
nothing!
Methods are where it’s at
Class Methods
add-class-methods branch
Alter $this
manipulate this branch
Abstract, Interface, Trait
Class Method
ZEND_ACC_IMPLICIT_ABSTRACT_CLA
SS
ZEND_ACC_STATIC
ZEND_ACC_EXPLICIT_ABSTRACT_CLA
SS
ZEND_ACC_ABSTRACT
ZEND_ACC_FINAL_CLASS ZEND_ACC_FINAL
ZEND_ACC_INTERFACE ZEND_ACC_PUBLIC
ZEND_ACC_TRAIT ZEND_ACC_PROTECTED
ZEND_ACC_PRIVATE
ZEND_ACC_CTOR
ZEND_ACC_DTOR
ZEND_ACC_CLONE
spl_ce_FilterIterator->ce_flags |=
ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
PHP_ME(DateTime, __construct, arginfo_date_create,
ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
1. globals
2. memory management
3. custom objects
4. object handlers
5. thread safety
Step 10: Advanced topics
1. in your header – use
ZEND_BEGIN|END_MODULE_GLOBALS
2. create the global access macro in your header
(copy and paste)
3. ZEND_DECLARE_MODULE_GLOBALS in
every file where you will use them
4. use the macro to access
COUNTER_G(basic_counter_value)); }
5. Create ginit/gshutdown functions if your globals
need initializing , etc
Global Variables (threads = evil)
emalloc( )
• allocates the specified number of bytes
safe_emalloc()
• like emalloc but adds a special protection against overflows
efree( )
• releases the specified block of memory back to the system
estrdup( )
• allocate a buffer and copy the string into that buffer
estrndup( )
• same as estrdup when you already know the length of the string
ecalloc( )
• allocates the number of bytes and initializes them to zero
erealloc( )
• resizes the specified block of memory
https://wiki.php.net/internals/zend_mm
1. clean up what you emalloc (C level destructor)
2. read wiki on how to make them extendable!
1. http://edit.php.net
2. http://svn.php.net/viewvc/phpdoc/en/trunk/reference/
3. PhD is awesomesauce
• http://doc.php.net/phd/
4. email pecl-dev@lists.php.net
1. who you are
2. what you wrote (with links to your code!)
3. why you think it should be in pecl
5. poke me (or other devs)
Document, PECL, release
Stuff I didn’t talk about
1. resources (use custom objects instead)
2. ini entries (just DON’T)
3. threading and parallel processing
4. engine hooking
5. streams and transports
6. Complex objects with handlers
About Me
 http://emsmith.net
 auroraeosrose@gmail.com
 twitter - @auroraeosrose
 IRC – freenode – auroraeosrose
 #phpmentoring
 #gophp7-ext
 https://joind.in/talk/56f05
Questions?
HELP WITH DOCS!
http://edit.php.net
http://wiki.php.net/internals
HELP WITH THE FUTURE
http://gophp7.org/gophp7-ext

More Related Content

What's hot

Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlHideaki Ohno
 
Using Jenkins for Continuous Integration of Perl components OSD2011
Using Jenkins for Continuous Integration of Perl components OSD2011 Using Jenkins for Continuous Integration of Perl components OSD2011
Using Jenkins for Continuous Integration of Perl components OSD2011 Jonas Brømsø
 
Unit 5
Unit 5Unit 5
Unit 5siddr
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension reviewjulien pauli
 
Getting groovy (ODP)
Getting groovy (ODP)Getting groovy (ODP)
Getting groovy (ODP)Nick Dixon
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS charsbar
 
How to inspect a RUNNING perl process
How to inspect a RUNNING perl processHow to inspect a RUNNING perl process
How to inspect a RUNNING perl processMasaaki HIROSE
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7julien pauli
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from DataMosky Liu
 
TDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsTDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsSheng-Hao Ma
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程Weber Tsai
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Elizabeth Smith
 
C++ for Java Developers (JavaZone 2017)
C++ for Java Developers (JavaZone 2017)C++ for Java Developers (JavaZone 2017)
C++ for Java Developers (JavaZone 2017)Patricia Aas
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrencyMosky Liu
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTSjulien pauli
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)charsbar
 
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練Sheng-Hao Ma
 

What's hot (20)

Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
 
Using Jenkins for Continuous Integration of Perl components OSD2011
Using Jenkins for Continuous Integration of Perl components OSD2011 Using Jenkins for Continuous Integration of Perl components OSD2011
Using Jenkins for Continuous Integration of Perl components OSD2011
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Unit 5
Unit 5Unit 5
Unit 5
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension review
 
Getting groovy (ODP)
Getting groovy (ODP)Getting groovy (ODP)
Getting groovy (ODP)
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
How to inspect a RUNNING perl process
How to inspect a RUNNING perl processHow to inspect a RUNNING perl process
How to inspect a RUNNING perl process
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
TDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on WindowsTDOH 南區 WorkShop 2016 Reversing on Windows
TDOH 南區 WorkShop 2016 Reversing on Windows
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!
 
C++ for Java Developers (JavaZone 2017)
C++ for Java Developers (JavaZone 2017)C++ for Java Developers (JavaZone 2017)
C++ for Java Developers (JavaZone 2017)
 
Hachiojipm11
Hachiojipm11Hachiojipm11
Hachiojipm11
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTS
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
 

Viewers also liked

PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"Fwdays
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodeSWIFTotter Solutions
 
Giving birth to an ElePHPant
Giving birth to an ElePHPantGiving birth to an ElePHPant
Giving birth to an ElePHPantMark Baker
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsMark Baker
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tigerElizabeth Smith
 
Programming with Cmdr. Chris Hadfield
Programming with Cmdr. Chris HadfieldProgramming with Cmdr. Chris Hadfield
Programming with Cmdr. Chris HadfieldMatthias Noback
 
Enterprise Architecture Case in PHP (MUZIK Online)
Enterprise Architecture Case in PHP (MUZIK Online)Enterprise Architecture Case in PHP (MUZIK Online)
Enterprise Architecture Case in PHP (MUZIK Online)Yi-Feng Tzeng
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityRyan Weaver
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Ryan Weaver
 
What's New In PHP7
What's New In PHP7What's New In PHP7
What's New In PHP7Petra Barus
 
Hexagonal architecture message-oriented software design
Hexagonal architecture   message-oriented software designHexagonal architecture   message-oriented software design
Hexagonal architecture message-oriented software designMatthias Noback
 
install PHP7 on CentOS7 by Ansible
install PHP7 on CentOS7 by Ansibleinstall PHP7 on CentOS7 by Ansible
install PHP7 on CentOS7 by AnsibleDQNEO
 

Viewers also liked (15)

PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better Code
 
Giving birth to an ElePHPant
Giving birth to an ElePHPantGiving birth to an ElePHPant
Giving birth to an ElePHPant
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
Programming with Cmdr. Chris Hadfield
Programming with Cmdr. Chris HadfieldProgramming with Cmdr. Chris Hadfield
Programming with Cmdr. Chris Hadfield
 
Enterprise Architecture Case in PHP (MUZIK Online)
Enterprise Architecture Case in PHP (MUZIK Online)Enterprise Architecture Case in PHP (MUZIK Online)
Enterprise Architecture Case in PHP (MUZIK Online)
 
Guard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful SecurityGuard Authentication: Powerful, Beautiful Security
Guard Authentication: Powerful, Beautiful Security
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 
What's New In PHP7
What's New In PHP7What's New In PHP7
What's New In PHP7
 
Hexagonal architecture message-oriented software design
Hexagonal architecture   message-oriented software designHexagonal architecture   message-oriented software design
Hexagonal architecture message-oriented software design
 
install PHP7 on CentOS7 by Ansible
install PHP7 on CentOS7 by Ansibleinstall PHP7 on CentOS7 by Ansible
install PHP7 on CentOS7 by Ansible
 

Similar to Php extensions

Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshopjulien pauli
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshopjulien pauli
 
Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Elizabeth Smith
 
TYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase frameworkTYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase frameworkChristian Trabold
 
Using spl tools in your code
Using spl tools in your codeUsing spl tools in your code
Using spl tools in your codeElizabeth Smith
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performancesjulien pauli
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13DanWooster1
 
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?NETWAYS
 
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...Puppet
 
20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-parisJohan De Wit
 
Puppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneDavid Glick
 

Similar to Php extensions (20)

Php extensions
Php extensionsPhp extensions
Php extensions
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
 
Spl in the wild - zendcon2012
Spl in the wild - zendcon2012Spl in the wild - zendcon2012
Spl in the wild - zendcon2012
 
TYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase frameworkTYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase framework
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
 
Using spl tools in your code
Using spl tools in your codeUsing spl tools in your code
Using spl tools in your code
 
Git::Hooks
Git::HooksGit::Hooks
Git::Hooks
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performances
 
Code with style
Code with styleCode with style
Code with style
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
Puppet Camp Duesseldorf 2014: Martin Alfke - Can you upgrade to puppet 4.x?
 
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
 
20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris
 
Puppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven Development
 
Hom Class
Hom ClassHom Class
Hom Class
 
Hom Class
Hom ClassHom Class
Hom Class
 
Hom Class
Hom ClassHom Class
Hom Class
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
 

More from Elizabeth Smith

Database theory and modeling
Database theory and modelingDatabase theory and modeling
Database theory and modelingElizabeth Smith
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tigerElizabeth Smith
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architectureElizabeth Smith
 
Taming the tiger - pnwphp
Taming the tiger - pnwphpTaming the tiger - pnwphp
Taming the tiger - pnwphpElizabeth Smith
 
Security is not a feature
Security is not a featureSecurity is not a feature
Security is not a featureElizabeth Smith
 
Mentoring developers-php benelux-2014
Mentoring developers-php benelux-2014Mentoring developers-php benelux-2014
Mentoring developers-php benelux-2014Elizabeth Smith
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with phpElizabeth Smith
 
Mentoring developers - Zendcon 2012
Mentoring developers - Zendcon 2012Mentoring developers - Zendcon 2012
Mentoring developers - Zendcon 2012Elizabeth Smith
 
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Elizabeth Smith
 
Event and signal driven programming
Event and signal driven programmingEvent and signal driven programming
Event and signal driven programmingElizabeth Smith
 

More from Elizabeth Smith (20)

Welcome to the internet
Welcome to the internetWelcome to the internet
Welcome to the internet
 
Database theory and modeling
Database theory and modelingDatabase theory and modeling
Database theory and modeling
 
Modern sql
Modern sqlModern sql
Modern sql
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
 
Taming the tiger - pnwphp
Taming the tiger - pnwphpTaming the tiger - pnwphp
Taming the tiger - pnwphp
 
Php’s guts
Php’s gutsPhp’s guts
Php’s guts
 
Lexing and parsing
Lexing and parsingLexing and parsing
Lexing and parsing
 
Hacking with hhvm
Hacking with hhvmHacking with hhvm
Hacking with hhvm
 
Security is not a feature
Security is not a featureSecurity is not a feature
Security is not a feature
 
Using unicode with php
Using unicode with phpUsing unicode with php
Using unicode with php
 
Mentoring developers-php benelux-2014
Mentoring developers-php benelux-2014Mentoring developers-php benelux-2014
Mentoring developers-php benelux-2014
 
Using unicode with php
Using unicode with phpUsing unicode with php
Using unicode with php
 
Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
 
Mentoring developers
Mentoring developersMentoring developers
Mentoring developers
 
Do the mentor thing
Do the mentor thingDo the mentor thing
Do the mentor thing
 
Mentoring developers - Zendcon 2012
Mentoring developers - Zendcon 2012Mentoring developers - Zendcon 2012
Mentoring developers - Zendcon 2012
 
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012
 
Mentoring developers
Mentoring developersMentoring developers
Mentoring developers
 
Event and signal driven programming
Event and signal driven programmingEvent and signal driven programming
Event and signal driven programming
 

Recently uploaded

Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxChloeMeadows1
 
Topology of the Network class 8 .ppt pdf
Topology of the Network class 8 .ppt pdfTopology of the Network class 8 .ppt pdf
Topology of the Network class 8 .ppt pdfAnushkaTripathi61
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?Linksys Velop Login
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideVarun Mithran
 
Premier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfPremier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfappinfoedgeca
 
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebiThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebJie Liau
 
Development Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appsDevelopment Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appscristianmanaila2
 
Statistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfStatistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfOndejSur
 
Thank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsThank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsrahman018755
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxabhinandnam9997
 
Case study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptxCase study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptxAnkitscribd
 
Reggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsrahman018755
 
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresenceCyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresencePC Doctors NET
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkklolsDocherty
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyDamar Juniarto
 

Recently uploaded (16)

Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptx
 
Topology of the Network class 8 .ppt pdf
Topology of the Network class 8 .ppt pdfTopology of the Network class 8 .ppt pdf
Topology of the Network class 8 .ppt pdf
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's Guide
 
Premier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfPremier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdf
 
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebiThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
 
Development Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appsDevelopment Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of apps
 
Statistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfStatistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdf
 
Thank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsThank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirts
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
Case study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptxCase study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptx
 
Reggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirts
 
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresenceCyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 

Php extensions

  • 1. PHP EXTENSIONS Making the language even better
  • 2. Congratulations! • You’ve decided to learn “down the stack” • You’ll learn more than you do “across the stack” • Your brain will hurt a bit • This will require you to be involved in your own learning process • It is HARD WORK to be good at anything new
  • 3. WARNING! The things shown here to apply to PHP 7 only!
  • 4. Why do extensions? • Talk to a C or C++ library • Modify the way the engine works (zend extensions usually) • Make slow parts of code run faster
  • 5. But I want to change the engine! Baby steps, baby steps
  • 7. But I don’t know C! 1. compiled 2. strictly typed 3. php internals do “hard” stuff 4. copy and paste! boilerplate and macros 5. cairo, pecl_http, date 6. Don’t do the hard stuff first! lxr.php.net https://php-lxr.adamharvey.name/source/
  • 8. But I want to learn C
  • 9. Also try: • http://www.learn-c.org/ • http://c.learncodethehardway.org/book/ • http://aelinik.free.fr/c/ Practice Practice Practice!
  • 11. Quick Setup Needs 1. compiler 2. sdk 3. tools 4. dependencies 5. code phpize is your friend!
  • 12. How to Compile an Extension 1. phpize 2. ./configure 3. make 4. make install 5. make test configure might require –with-php-config=/path/to/something but…
  • 13. But wait – there’s more! • Compile your own PHP source, use a –prefix  /usr/local/php-7.0-debug-zts is one I use  I also have 20 php’s installed  • We want developer specific flags  --enable-maintainer-zts and --enable-debug  optionally –enable-gcov • install gdb and valgrind and optionally lcov • this is easy on Ubuntu and similar systems where packages are easy to get • You can also compile php with clang instead of gcc and do things like use static analysis
  • 14. Rasmus to the Rescue! • https://github.com/rlerdorf/php7dev/blob/master/README.md tl;dr 1. install virtualbox 2. install vagrant 3. git clone https://github.com/rlerdorf/php7dev.git 4. cd php7dev 5. vagrant up 6. vagrant ssh 7. makephp 7
  • 15. How to Play along git clone https://github.com/auroraeosrose/php-extensions- code.git git clone git://github.com/auroraeosrose/php- extensions-code.git git checkout scaffolding phpize ./configure make make test
  • 16. Let’s write an extension! But wait – there’s more….
  • 17. 1. Set up compile environment 2. Write a module definition 3. Learn about the PHP lifecycle 4. Learn about zvals 5. Add functions 6. ??? 7. Profit! Every Other Extensions Talk
  • 19. Which do YOU want?
  • 20. 1. Do something you can’t do in userland 2. Utilize a C library 3. Make slow code faster Maybe you should just use ffi! Step 1. Why?
  • 21. What is FFI? • Foreign function interface • Java calls it JNI • HHVM calls it HNI • Python calls it “ctypes” (do not ask, stupidest name ever) • C# calls it P/Invoke • Ruby calls it FFI • PHP calls it…
  • 22. FFI
  • 23. Oh wait… • php’s ffi is rather broken (last release is 2004-01-20) • php’s ffi has no maintainer (ilia and wez were doing it) • It needs some TLC • There’s MFFI but it’s not done  https://github.com/mgdm/MFFI • Are you interested and not afraid? See me!
  • 24. 1. I hate parsing URIs 2. PHP’s parse_url is… not the best 3. How about an extension that wraps something that parses uris in an excellent fashion 4. RESEARCH TIME Step 2. What
  • 26. C library to the rescue! • uriparser.sourceforge.net • strictly RFC 3986 compliant • available on many systems as packages • cross platform • documented http://uriparser.sourceforge.net/doc/html/
  • 27. 1. Think about what the API should be 2. Look at the C APIs but don’t mimic them 3. Write an example of how you WANT it to work 4. Write more then one example! 5. Turn these examples into your first tests 6. Yes this is TDD Step 3. How
  • 28.
  • 29. 1. This is copy and paste 1. config.m4 & config.w32 2. macros for version api changes if necessary 3. main module file (php_{$ext}.c) 4. main header file (php_{$ext}.h) 2. Compile it and test! Step 6. Extension Scaffolding
  • 32. Scaffolding rules 1. make sure you name your files in a standard way 2. document! use a license header, proto statements 3. read the coding standards http://lxr.php.net/xref/PHP_5_6/CODING_STANDA RDS 4. FOLLOW THE CODING STANDARDS 5. use version control early on – github is easy!
  • 33. php –d extension=myext.so –m The scaffold extension should show up in the list Make sure to 1. define a version constant 2. read and use PHP code standards Check if it works
  • 34. 1. run-test.php 2. make test will magically have output more at http://qa.php.net/write-test.php and docs at http://qa.php.net/phpt_details.php Step 7. Write the test
  • 36. Let’s take a break here for some semi-live demos…
  • 37. Zval The guts behind PHP’s type system
  • 38. Typing systems compared Static Typing (C) • Variables must be declared before use • Variables must be given a type at declaration • “compile time” checking Dynamic Typing (PHP) • Variables don’t have to be declared before use • Variables can change types • “run time” checking
  • 39. zval
  • 41. For more on the new zval https://nikic.github.io/2015/05/05/Internal-value-representation-in- PHP-7-part-1.html
  • 42. long any numeric double numeric with decimal char* + size_t (length) strings, binary Hashtable dictionaries, arrays,structs object any complicated type
  • 43. For more on the new string type http://jpauli.github.io/2015/09/18/php-string-management.html
  • 44. How do I get C types from a ZVAL? Z_LVAL(zval) Z_LVAL_P(zval_p) Z_LVAL_PP(zval_pp) Z_BVAL(zval) Z_BVAL_P(zval_p) Z_BVAL_PP(zval_pp) Z_DVAL(zval) Z_DVAL_P(zval_p) Z_DVAL_PP(zval_pp) Z_STRVAL(zval) Z_STRVAL_P(zval_p) Z_STRVAL_PP(zval_pp) Z_STRLEN(zval) Z_STRLEN_P(zval_p) Z_STRLEN_PP(zval_pp) Z_ARRVAL(zval) Z_ARRVAL_P(zval_p) Z_ARRVAL_PP(zval_pp) Z_OBJ(zval) Z_OBJ_P(zval_p) Z_OBJVAL_PP(zval_pp) Z_OBJ_HANDLE(zv al) Z_OBJ_HANDLE_P(zval _p) Z_OBJ_HANDLE_PP(zval_ pp) Z_OBJ_HT(zval) Z_OBJ_HT_P(zval_p) Z_OBJ_HT_PP(zval_pp) Z_OBJCE(zval) Z_OBJCE_P(zval_p) Z_OBJCE_PP(zval_pp) Z_OBJPROP(zval) Z_OBJPROP_P(zval_p) Z_OBJPROP_PP(zval_pp) Z_TYPE(zval) Z_TYPE_P(zval_p) Z_TYPE_PP(zval_pp)
  • 45. My extension does nothing! Back to our regularly schedule content
  • 46. 1. tell it to link to our C library 2. add a function 3. learn how to get data 4. learn how to return data Step 8. Actually do something
  • 47. I hate autotools… • Also known as the gnu build system • provider of much pain, but much good use as well • autoconf – generates a configure script (we cheat with phpize on shared extensions)  makes a configure we run to set up our information, mainly a config.h file • automake – creates makefiles • libtool – creates static and dynamic libraries • Windows? Well php wrote it’s own version of autotools – in jscript (windows javascript variant)
  • 48. Anatomy of a Function
  • 49. Wait – what was that? • Define your function in C  use a special call to parse parameters passed by the user  use a special zval to return data to the user • Tell PHP your extension provides this function  put it in your “giant struct of doom” that lists them all  send it to php when in your module struct • Tell PHP what arguments your extension provides  If your argument information and zpp argue users will be angry  Yes it sucks you can’t just do one 
  • 50. php type code c type array or object a zval * boolean b zend_bool class C zend_class_entry * double d double callable f zend_fcall_info andzend_fcall_info_cache array or HASH_OF(object) H HashTable* array h HashTable* integer l zend_long integer L zend_long with LONG_MAX, LONG_MIN limits object o zval * object of specific type O zval *, zend_class_entry string (no null bytes) p char*, size_t resource r zval * string (possible null bytes) s char*, size_t actual zval z zval * actual zval Z zval**
  • 51. zend_parse_parameters type code variable args (any) * int, zval** variable args (1 or more) + int, zval** | anything after is optional, use defaults / use SEPARATE_ZVAL_IF_NOT_REF doesn’t apply to b, l, and d ! C NULL for zval null
  • 52. return_value RETURN_RES(l) RETURN_BOOL(b) RETURN_NULL() RETURN_LONG(l) RETURN_DOUBLE(d) RETURN_STRING(s) RETURN_STRINGL(s, l) RETURN_EMPTY_STRING() RETURN_ZVAL(zv, copy, dtor) RETURN_FALSE RETURN_TRUE RETVAL_RES(l) RETVAL_BOOL(b) RETVAL_NULL() RETVAL_LONG(l) RETVAL_DOUBLE(d) RETVAL_STRING(s) RETVAL_STRINGL(s, l) RETVAL_EMPTY_STRING() RETVAL_ZVAL(zv, copy, dtor) RETVAL_FALSE RETVAL_TRUE
  • 54. Now to visit the attach-library branch…
  • 55. 1. namespaces 2. classes 3. methods 4. constants Step 9. Make it shiny
  • 56. Classes 1. name, parent, and flags 2. hashtables of methods, default methods, static methods 3. hashtables of static properties, default properties, and properties 4. object handlers 5. union of either file information, or internal structures (for internal classes)
  • 57.
  • 58.
  • 60. Lifecycle Let’s take a moment to learn about how PHP works internally
  • 61. Lifecycle PHP stops MSHUTDOWN – for each extension RSHUTDOWN – for each request cleanup after test.php RINIT – for each request execute test.php MINIT – for each extension request/parse test.php PHP starts php test.php
  • 62. Lifecycle Threaded PHP stops MSHUTDOWN – for each extension request index.php request foo.php RINIT – for each request • execute test.php RSHUTDOWN – for each request • cleanup after test.php RINIT – for each request • execute test.php RSHUTDOWN – for each request • cleanup after test.php MINIT – for each extension apache starts
  • 67. My class does nothing! Methods are where it’s at
  • 72. Abstract, Interface, Trait Class Method ZEND_ACC_IMPLICIT_ABSTRACT_CLA SS ZEND_ACC_STATIC ZEND_ACC_EXPLICIT_ABSTRACT_CLA SS ZEND_ACC_ABSTRACT ZEND_ACC_FINAL_CLASS ZEND_ACC_FINAL ZEND_ACC_INTERFACE ZEND_ACC_PUBLIC ZEND_ACC_TRAIT ZEND_ACC_PROTECTED ZEND_ACC_PRIVATE ZEND_ACC_CTOR ZEND_ACC_DTOR ZEND_ACC_CLONE spl_ce_FilterIterator->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS; PHP_ME(DateTime, __construct, arginfo_date_create, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
  • 73. 1. globals 2. memory management 3. custom objects 4. object handlers 5. thread safety Step 10: Advanced topics
  • 74. 1. in your header – use ZEND_BEGIN|END_MODULE_GLOBALS 2. create the global access macro in your header (copy and paste) 3. ZEND_DECLARE_MODULE_GLOBALS in every file where you will use them 4. use the macro to access COUNTER_G(basic_counter_value)); } 5. Create ginit/gshutdown functions if your globals need initializing , etc Global Variables (threads = evil)
  • 75. emalloc( ) • allocates the specified number of bytes safe_emalloc() • like emalloc but adds a special protection against overflows efree( ) • releases the specified block of memory back to the system estrdup( ) • allocate a buffer and copy the string into that buffer estrndup( ) • same as estrdup when you already know the length of the string ecalloc( ) • allocates the number of bytes and initializes them to zero erealloc( ) • resizes the specified block of memory https://wiki.php.net/internals/zend_mm
  • 76. 1. clean up what you emalloc (C level destructor) 2. read wiki on how to make them extendable!
  • 77. 1. http://edit.php.net 2. http://svn.php.net/viewvc/phpdoc/en/trunk/reference/ 3. PhD is awesomesauce • http://doc.php.net/phd/ 4. email pecl-dev@lists.php.net 1. who you are 2. what you wrote (with links to your code!) 3. why you think it should be in pecl 5. poke me (or other devs) Document, PECL, release
  • 78. Stuff I didn’t talk about 1. resources (use custom objects instead) 2. ini entries (just DON’T) 3. threading and parallel processing 4. engine hooking 5. streams and transports 6. Complex objects with handlers
  • 79. About Me  http://emsmith.net  auroraeosrose@gmail.com  twitter - @auroraeosrose  IRC – freenode – auroraeosrose  #phpmentoring  #gophp7-ext  https://joind.in/talk/56f05

Editor's Notes

  1. I mentor PHP developers into becoming C developers – because other PHP devs have done that for me If you want to move on and do more with extensions after this talk please talk to me – I also sit on freenode all day and answer questions and give feedback – always always want more code monkeys and fresh blood in any project and looking at extensions makes me sad – 99% suck
  2. Give my short talk about why learning “down the stack” is so important and why more developers need to stop asking should I learn python or perl it’s better to learn in a domain entirely different than what you are currently doing if you do desktop learn web, if you learn web do desktop or mobile if you do PHP, don’t learn “across” (perl, python, ruby) learn DOWN java, C#, go, rust obj-c, C, c++ assembler the old gurus of C who built what we play with are dying off (do the math, how old is rasmus?) there won’t be hand holding, but a good mentor (for now me) will help you learn what you need to know
  3. PHP 7 will be breaking all the rules here, changing things in a fundamental manner, just something to keep in mind We’re working on a project to make migrating to PHP7 well documented and easy when the time comes and also working on ways to improve extensions in general
  4. This is the reason we have PHP extensions to hit the lower level parts of the code that are so important But the top reason is the #1 reason we write PHP extensions
  5. This is usually the first thing people think of when they want to “get involved with PHP internals” But you will have a far easier time of things if you start with extensions
  6. This is the proper path to get involved in PHP and the language - learning each piece of the stack step by step will make you not only a better program, and understand the language but it will make you a better part of the community
  7. This is the #1 argument I hear – but really is not anything you need to worry about c98 people! you can use some c99 stuff but declarations MUST go at the top of blocks (that’s really good coding standards anyway) although this will be moot when Microsoft finally gets it’s CTP for 2015 just like php itself turn all your errors on when compiling (-wall is your friend) and try to code clean you don’t have to “know C” anymore then you have to “know PHP” to write a wordpress plugin if you have the very basics of what to do it’s not hard PHP takes care of a lot of the heavy lifting – from how to parse parameters coming in and how to shove data into someplace going out… to how to do fancy objects Unless you’re doing something REALLY evil (an opcode cache, changing the way the engine works, threading) most of this stuff has already been done for another extension, it’s just a matter of finding the code – compile and test btw, all the code generators out there currently suck – most don’t do test generation, doc generation, or use the proper apis
  8. This is the book you want it’s affectionately called the C bible if you walk through this book and do the exercise you’ll get the basics of C
  9. These are some pretty good free resources for learning C – walking through the two books and the online tutorial will get you a good portion of the way there remember programming is thinking as much as writing code as if you play piano or dance you must practice practice practice
  10. So you’ll need to actually have an environment set up to compile PHP on I will say right now for your first foray into extensions you will be happiest on linux a VM is fine, in a debian/ubuntuish flavor because you’ll get a lot more help and support Also programming for windows and OSX is something you’ll need to learn before you finalize that extension but are much harder (yes, even OSX is harder – to do it right on there you use homebrew or something similar to install a linux stack – would be easier at first just to set up a linux vm)
  11. This is the same and yet different on every system and we’re not going to go into it a whole lot – this should have been homework before you came ;) Basically you need a compiler – xcode on mac, vc(2008) express on windows, gcc something on linux – this is different for every system You also need the sdk and headers for your system – those will be put on with xcode, you’ll need the 6.1 windows sdk for windows Then you need autotools – bison, and re2c to build PHP On mac or linux you can use phpize to build extensions – You CAN do this on windows as well except that for some stupid reason the proper files are not shipped with windows binary builds (stupid) Then you need any depedencies (to build PHP as a base you need iconv, zlib, and libxml2 at a bare minimum) After you build PHP on windows you can use phpize (it will be generated for you) and makes life so much easier
  12. make a note that windows does not need the ./ before configure and uses nmake instead of make (otherwise identical) Note that to use a specific PHP install use /full/path/to/phpize and –with-php-config=/usr/local/php5/bin/php-config Note this does shared extensions only – then again most of the extensions you’ll work on should probably be shared
  13. So although I wont’ whine about it today – if you really want to do extensions properly you need to have your own php compile you need to not be afraid of gcc and clang you need to make sure you test and test and test
  14. There, now we’ve switched to using a precompiled debug zts version of php 7.0 WOOHOO There aren’t (yet) other box versions/providers available – this is ongoing work (more on gophp7-ext later)
  15. I’m putting parts of this code onto my github account – each section I talk about – scaffolding, adding a function, ext, will have a different branch – feel free to clone and play These aren’t necessarily complicated extensions but they do follow PHP CS, have all the copy and paste you need and do compile (I think)
  16. So the part we’re all excited about – let’s write an extension! I’ll just get some code and then you copy and compile it and then…
  17. If you’ve ever seen another PHP extensions talk they dive into how to use the zend engine and how things work and such PHP is to C as wordpress is to PHP – makes any idiot able to write a plugin for it ;) you don’t necessarily HAVE to know how the internals work – you just have to know the right calls to make! So although I might tell you about SOME of the internals how and why, for the most part this will be “how to do it” not “why you do it” Because PHP is a ball of rusty nails ;)
  18. In addition this is the absolutely wrong way to approach writing PHP extensions! Actually it’s the wrong way to approach writing LOTS of things do you start out writing a website worrying about how to make a db connection before you’ve designed the database and created the schema? do you create the schema before you have wireframes? just because we’re making a product in a different language doesn’t mean the rules change
  19. this is why you really need to think about what you’re doing – being able to use the extension is not really enough… just wrapping a C api is a good way to give yourselves headaches of a horrible nature Please be the solution, not the problem We need no more painful APIs in PHP
  20. so these are the reasons you’d write a PHP extension as we talked about before – you want to use a C library, you want to make something process intensive faster, you want to hook into the engine itself there aren’t other reasons to do an extension wait? what is FFI?
  21. So many languages support this idea of calling into usually C code Then they usually put a layer of regular code “on top” to make APIS non painful This can be useful it also tends to be slower
  22. before you get into extension writing – if you just want an ffi wrapper and are just going to call the exact C calls from an existing library why go to the trouble of writing an extension? ffi is pretty great but a bit of a flakey extension yet, but it’s identical to python’s “ctypes” which is a stupid name, it’s really ffi I hear al lthe time about how “great” python is because of ctypes, frankly I beg to differ. Part of wrappign a C extension is translating the C calls into something far more “phpish”
  23. oh ffi is cool and so needs a maintainer
  24. so this is what we want to do – write an extension that wraps a good C uri parsing library
  25. so you need to do your research right? there are multiple C parsing libraries, joyent has one and there are some nice c++ ones, but for simple well laid out C uriparser seems to win – also it’s really nice use your internet tools – when you started PHP I’m sure you had books and stuff on speed dial you will need to do the same for C
  26. SO this is a VERY nice C library for parsing uris according to the spec – USEFUL AS ALL GETOUT cross platform, well maintained, easy to use – don’t let the sourceforge URL fool you, it’s in git 
  27. C++ APIs or similar wrappers in python, perl, ruby, etc are a better place to look for api ideas – try a couple of ways of using the apis as well really think about what kinds of apis and code you’re looking for – so I was looking at wrapping a small library (uriparser.sourceforge.net) and one of the things I did first was sit down and write some rough almost pseudo-code of what the extension might look like
  28. uriparser.sourceforge.net – a simple uri parser library that strictly conforms to rfc questions to ask yourself as you write these examples do I want namespaces? will this be an object oriented api or a procedural style api? do I want to do the extra work of a dual api? (such as date or mysqli?) these decisions are usually pretty easy to figure out once you actually try to write the kind of code you want to work
  29. PHP is 90% copy and paste, the main copy and paste stuff is all scaffolding for an extension so we’ve figure out what we want to write and how we want to write it, now we need to have scaffolding in place for it talk about our 4 files, the scaffold example - show the files quickly to show what normally goes in a header, some PHP CS rules, et al
  30. DO BOTH unless you’re absolutely certain that whatever you’re writing will only work on one system or the other m4 is autotools stuff, but the w32 are very easy to write as well, they’re just jscript (windows javascript dialect) with some special functions for things like checking headers and adding libs, etc talk about with vs. enable
  31. this is the very basic items you can have in your struct to define what you module is and what it does STANDARD_MODULE_HEADER_EX allows you to add ini entries and depedencies to your module definition using STANDARD_MODULE_PROPERTIES_EX allows you to add globals what the globals are, a ginit and a gshutdown – plus a “post deactivate” method that basically never gets used ;)
  32. Just some general rules for you to take a look at even if your extension is not going into PHP proper the more time you take to properly document your code the happier you will be
  33. how to see if what you’ve been playing with will actually work This should load your boring extension without doing anything fancy, just allow it to show up in the modules list you can actually do a test case for this with extension_loaded or get_loaded_modules if you’re so inclined
  34. everybody should ALWAYS test their extensions – test test test turn debugging on, turn memory leaks on - run your tests if they fail you’ll get a bunch of extra files from the tests system available that make things very easy to debug, a diff file, .out file, even an .sh file to run the test exactly like it was run the first time no .bat file yet… yes I have a patch for that
  35. These are very basic functional style tests there are a bunch of different sections for each one – the important thing to remember is always include a skipif anything in “tests” will be run so it’s ok to put things in directories for order write tests for everything you can think of! this is my standard test to check my phpinfo (MINFO) function
  36. Look at the code and look at the compile
  37. NOTE: again there were many underlying changes made to php’s zvals for php 7 I’m not going to go into all the changes but I may mention a few we’re going to detour just a moment to learn something about PHP’s guts
  38. But wait – PHP is sitting on C we are somehow translating C types to PHP types – how is this magic accomplished?
  39. Our zval is a giant struct of doom for those of you who don’t know what a union is, A union, is a collection of variables of different types, just like a structure. However, with unions, you can only store information in one field at any one time. You can picture a union as like a chunk of memory that is used to store variables of different types. Once a new value is assigned to a field, the existing data is wiped over with the new data. This is what everything you do in C goes into!
  40. PHP 7 has totally flipped around how a zval is structured
  41. PHP 7 has totally flipped around how a zval is structured Simple values do not require allocation and don’t use refcounting. There is no more double refcounting. In the object case, only the refcount in the object is used now. Because the refcount is now stored in the value itself, the value can be shared independently of the zval structure. A string can be used both in a zval and a hashtable key. There is a lot less indirection, i.e. the number of pointers you need to follow to get to a value is lower. Discuss heap vs. stack memory here
  42. So basically with an extension (especially one wrapping a library) what you’re doing is taking C variables and exposing them to php land by turning them into zvals so a “zval” in PHP has a union that can have the value of what is inside – something you’ll need to do when you create your extension is figure out how to “translate” that to a PHP type and how to handle it
  43. In C, strings are simple NULL-terminated char arrays, like you know. However, when designing a scripting language such as PHP, the need to manage those strings arises. In management, we think about classical operations, such as concatenation, extension or truncation ; and eventually more advanced concepts, such as special allocation mechanisms, string interning or string compression. As length are typed on a size_t variable, they weight {platform size} bytes ! Whatever the platform. One of the PHP 5 problems is then solved : under a CPU64, string length will be 8 bytes (64 digits) for every platform (this is one of the definition of the C size_t type). Strings are refcounted ! In PHP 7, strings are refcounted (as well as many other primitive types). That means that interned strings are still relevant, but less : PHP layers can now pass strings from one to the other, as strings are refcounted, we are plainly sure that noone will accidentaly free the string as this latter is still used elsewhere (until doing an error on purpose).
  44. p is for pointer (that’s good enough for me) these are helper macros to get the data OUT of that union of doom that you need, it’s also how you get zval types and other fun stuff note there are even MORE then this, but these are the ones you’ll use most often PHP is governed by macros and more macros, which is why it’s important to look at existing PHP extensions since 95% of the macros are NOT documented The PP macros have been ripped out of php7 because we no longer have pointer pointers all over the place And the macros without the pointer are used a LOT more than they used to be Booleans have internally changed – you should always check for IS_FALSE and IS_TRUE instead of considering as a Boolean value, and doing an lval on it will break
  45. Now let’s make our extension like… actually do something
  46. So we’re going to actually write a function for our uriparser library that does something extremely simple – we’re going to register a function to tell us the uriparser library version
  47. Here show all the lines required to do one thing – link into the library mention how other options are thin on the ground, although cmake is gainin some major traction about 2008 there was an attempt to port php’s build system to cmake sadly cmake was not really ready for it it IS ready for it now (hhvm and others all use cmake) But again that’s a monstrous project and you’re fighting a battle gains? one build system for everything ,not maintaining our own configure system for windows, easier integration into ecosystems
  48. you need to do three things to add a function to your extension define it’s arguments – this is for reflection define it’s body put it inside a function struct arginfo must have the begin and end arginfo then you add additional arguments as desired in between if you have optional arguments, use begin_arginfo_ex you can send by val or reference or do typehinting with arginfo as well
  49. SO a lot of this is implementation detail issues so in PHP you use this macro – all it does is rename your function name to something that won’t collide evilly, and define a bunch of C parameters you’re getting passed in 
  50. there are even more than this in php7 strings move to use the more correct The IS_LONG type now uses a zend_long value instead of an ordinary C long. The reason behind this is that on 64-bit Windows (LLP64) a long is only 32-bit wide, so PHP 5 ended up always using 32-bit numbers on Windows. PHP 7 will allow you to use 64-bit numbers if you’re on an 64-bit operating system, even if that operating system is Windows.
  51. so you can also do “zend_parse_parameters_ex” the only thing you can do it with is QUIET there are a couple of reasons for doing this – mostly nesting and overloaded calls Note that variable args have dropped a pointer!
  52. This is macro hell – PHP is macro hell every PHP function (or method) has a return value available to you – an automatically NULL zval that you need ot manipulate in order to give information back it’s called return_value you manipulate these return value zvals to get data back into PHP userland the one thing that is Retval_res used to be retval_resource Retval string no longer has the duplicate option
  53. When you start to want to return complex data things get a little more complicated – this is where array and object init come in there are also ways to array_init with a specific length or object_init_ex which allows you to choose the type of object you’re creating there are a bunch more of these zend_API.h is your lifeblood for how to use these things, along with Note that strings used to have the option of saying “duplicate me” or not, now you don’t worry about it, because you’re using a zend_string with refcounts and such
  54. Look at the code and look at the compile make clean, switch branch, You have to install uriparser by hand That means download and build – it has a pretty straightforward system You can –disable-doc and –disable- I forget (check in code) to ignore bad things
  55. Now we move on to more complex parts of the code, methods that really DO something remember we should start by writing tests for it
  56. Zend_object can be a variable length now! These can lead to far more complex code if you’re doing evil with objects We don’t really go over object handlers and other crazy stuff because that’s beyond the scope here of our learning, but something to look up
  57. TO do a class – create and register it’s CE in minit put it in another file – will keep yourself sane instead of having 300 mile long files some people whine that this makes it harder to use static stuff, since each file is compiled into it’s own “unit” and then linked but modern compilers and linkers make the overhead on this moot – better to be organized!
  58. so this is how you would do your minit function – this would go into php_uriparser.c where the other code displayed would be in uri.c – where all our code for our uri class is going it is generally a good idea to keep arginfo and methods to gether as well in the code, so when one changes you remember to change the other remember stuff must be declared in order to be used too! the namespace declaration and the PHP_MINIT declaration go into the header file I often do a private header file for things like that – or do an api file if I allow things in my extension to be used by say other extensions
  59. So this has ONLY the basics – explain how the minit works then let’s talk lifecycle
  60. Deep breath – let’s talk about those things we put in the module struct Each are run at a different point in time let’s also talk a wee bit about structure? sapis?
  61. so this is the lifecycle of PHP each of these items has a different important role to play what you need to remember is that minit and mshutdown are called in the opposite order that they are loaded, but you can’t depend on other extensions being around unless you have registered deps (remember way back in the main struct when we talked about deps? this flow is also true for prefork php webservers But then we get into threads
  62. When we add threading it gets a little more difficult, because minit/mshutdown are only called when apache is restarted there’s also ginit and gshutdown but they’re broken
  63. There are multiple declarations to help with this – the ZEND_STRS is a helper macro – again macro hell
  64. So this has ONLY the basics – explain how the minit works then let’s talk lifecycle
  65. Class constants are another thing that’s pretty easy to do – global constants are evil, do NOT do
  66. then we add some constants for fun
  67. Now let’s make our extension like… actually do something
  68. Methods have several components but look very close to functions that we did earlier. There is a getThis which is available inside that will give you the zval for the class notice how similar this is to functions!
  69. go over the method stuff just a bit
  70. getTHis is the way you get “this” – notice that no matter how you declare your properties in MINIT, you can “juggle” the vale around depending on what you set it to
  71. go over the method stuff just a bit
  72. Note – traits in extensions are basically broken 
  73. these are some more advanced topics
  74. A PHP extension's globals are more properly called the "extension state", since most modules must remember what they're doing between function calls. The "counter" extension is a perfect example of this need: The basic interface calls for a counter with a persistent value. A programmer new to Zend and PHP might do something like this in counter.c to store that value: This is changed significantly in the way this is stored – as we’re using thread local globals in our thread safe build
  75. efree, emalloc, ecalloc – you can find good documentation on these manual/en/internals2.memory.management.php zend is taking care of all the memory stuff for you – allocating a larger chunk, cleaning up at the end of the request (but still, efree dammit) Often, memory needs to be allocated for longer than the duration of a single request. These types of allocations, called persistent allocations because they persist beyond the end of a request, could be performed using the traditional memory allocators because these do not add the additional per-request information used by ZendMM. Sometimes, however, it's not known until runtime whether a particular allocation will need to be persistent or not, so ZendMM exports a set of helper macros that act just like the other memory allocation functions, but have an additional parameter at the end to indicate persistence. If you genuinely want a persistent allocation, this parameter should be set to one, in which case the request will be passed through to the traditional malloc() family of allocators. If runtime logic has determined that this block does not need to be persistent however, this parameter may be set to zero, and the call will be channeled to the perrequest memory allocator functions.
  76. you’ll do a lot of zend_fetch_object stuff to pick this stuff
  77. Documentation is probably the most important part of the process, but I’ll still leave it for last If you’ve been writing examples and tests and protos and arginfo all along as I’ve whined about, you’re already 90 percent of the way there with docs, seriously the easiest way to do this would be to use a generator, however there aren’t any GOOD generators available right now so just go to svn and copy another extensions stuff – everything is created with PhD so you can test stuff for pecl you can put your code anywhere, for phpdoc you need to get your docs roughed out then ask them to be put in svn also mention readthedocs and the fact that pecl has licensing restrictions and we need a packagist
  78. Go into here about how resources work (an integer pointer to a global table holding resources… or doing some other evil resource storage – basically you’re storing and throwing about pointers and they’re slow (DO NOT) ini entries are a horrible thing – the use cases are extremely small threading and such I can rant about for quite a bit and finally you can override parts of the engine from extensions – this is why xdebug and things like intercept work but they’re a bit beyond the scope of this talk
  79. There is SOOO much more you can do from hooking objects to hooking the engine!
  80. There is SOOO much more you can do from hooking objects to hooking the engine!