SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
Create your own PHP extension, step by step
Patrick Allaert, Derick Rethans, Rasmus Lerdorf




           phpDay 2012 Verona, Italy
Patrick Allaert
●   Founder of Libereco
●   Playing with PHP/Linux for +10 years
●
    eZ Publish core developer
●   Author of the APM PHP extension
●   @patrick_allaert
●   patrickallaert@php.net
●   http://github.com/patrickallaert/
●   http://patrickallaert.blogspot.com/
Derick Rethans
●   Dutchman living in London
●   PHP Engineer/Evangelist for 10gen (the MongoDB
    people), where I also work on the MongoDB PHP
    driver.
●   Author of Xdebug
●   Author of the mcrypt, input_filter, dbus, translit
    and date/time extensions
Workshop overview
●   Brief reminders about PHP architecture
●   Configure your environment
●   Grab the example extension
●   Do some exercises while seeing a bit of theory
PHP architecture
Configuring your environment
●   Debian-like:
$ sudo apt-get install php5-dev
Download the sample extension
a) Using git:
$ git clone
git://github.com/patrickallaert/
PHP_Extension_Workshop.git
b) Download archive at:
https://github.com/patrickallaert/PHP_Extension_Wo
rkshop/downloads
Minimal C code (myext.c)
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include   "php.h"
#include   "php_ini.h"
#include   "ext/standard/info.h"
#include   "php_myext.h"

zend_module_entry myext_module_entry = {
    STANDARD_MODULE_HEADER,
    "myext",
    NULL, /* Function entries */
    NULL, /* Module init */
    NULL, /* Module shutdown */
    NULL, /* Request init */
    NULL, /* Request shutdown */
    NULL, /* Module information */
    "0.1", /* Replace with version number for your extension */
    STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_MYEXT
ZEND_GET_MODULE(myext)
#endif
Compilation
Prepare build environment:
1. $ phpize
Configure the extension:
2. $ ./configure
Compile it:
3. $ make
Install it (may require root):
4. $ make install
Verify installation
$ php -d extension=myext.so -m
You should see “myext” as part of the loaded
extensions.
Minimal config.m4
dnl config.m4 for myext


PHP_ARG_ENABLE(myext, whether to enable myext
support,
[    --enable-myext       Enable myext support])


if test "$PHP_MYEXT" != "no"; then
    PHP_NEW_EXTENSION(myext, myext.c,
$ext_shared)
fi
Exercise one: fibonacci (1/7)
●   F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1
Exercise one: fibonacci (2/7)
function fibo($n) {
    switch ($n)
    {
        case 0:
        case 1:
            return $n;
    }

    return fibo($n-2) + fibo($n-1);
}
Exercise one: fibonacci (3/7)
Exercise one: fibonacci (4/7)
Exercise one: fibonacci (5/7)
Exercise one: fibonacci (6/7)
Exercise one: fibonacci (7/7)
Compile:
$ make
Install:
$ make install
Test:
$ php -d extension=myext.so 
  -r 'echo fibonacci(35), “n”;'
9227465
Exercise one: fibonacci solution
The full changes required to implement the fibonacci
function are available at:
http://tinyurl.com/PHP-ext-fibonacci
zend_parse_parameters
●   Handles the conversion of PHP userspace variables
    into C ones.
●   Generate errors in the case of missing parameters
    or if the type is wrong.
zend_parse_parameters
●   Second parameter describes      Type       Cod Variable type
                                                e
    the type of the parameter(s)    Boolean     b   zend_bool
    as a string composed of         Long        l   long
    characters having all a         Double      d   double

    special meaning.                String      s   char *, int (length)
                                    Path        p   char *, int (length)
●   To mark the start of optional   Class       C   zend_class_entry*
                                    name
    parameter(s), a pipe (“|”)
                                    Resource    r   zval*
    character is used.              Array       a   zval*
                                    Object      o   zval*
                                    zval        z   zval*
                                    Zval        Z   zval**
                                    pointer
                                    Callback    f   zend_fcall_info,
                                                    zend_fcall_info_cache
zend_parse_parameters examples
●   sleep(), usleep(), func_get_arg():
    zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
    &long)
●   bin2hex(), quotemeta(), ord(), ucfirst():
    zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
    &str, &str_len)
●   str*pos():
    zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l",
    &haystack, &haystack_len, &needle, &offset)
●   var_dump():
    zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+",
    &args, &argc)
●   file_put_contents()
    zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pz/|
    lr!", &filename, &filename_len, &data, &flags,
    &zcontext)
OpenGrok (1/2)
●   Your best friend to browse PHP's source code:
    http://lxr.php.net/
OpenGrok (2/2)
zval (=== _zval_struct)
struct _zval_struct {
   /* Variable information */
   zvalue_value value; /* value */
   zend_uint refcount__gc;
   zend_uchar type; /* active type */
     zend_uchar is_ref__gc;
};

typedef union _zvalue_value {
  long lval; /* long value */
  double dval; /* double value */
  struct {
    char *val;
    int len;
  } str;
  HashTable *ht; /* hash table value */
  zend_object_value obj;
} zvalue_value;
Types
●
    IS_NULL
●
    IS_LONG
●   IS_DOUBLE
●   IS_BOOL
●
    IS_ARRAY
●
    IS_OBJECT
●   IS_STRING
●
    IS_RESOURCE
●
    IS_CONSTANT
●   IS_CONSTANT_ARRAY
●
    IS_CALLABLE


●   http://lxr.php.net/xref/PHP_TRUNK/Zend/zend.h#IS_NULL
Access macros
Z_TYPE(zval)             (zval).type
Z_LVAL(zval)             (zval).value.lval
Z_BVAL(zval)             ((zend_bool)(zval).value.lval)
Z_DVAL(zval)             (zval).value.dval
Z_STRVAL(zval)           (zval).value.str.val
Z_STRLEN(zval)           (zval).value.str.len
Z_ARRVAL(zval)           (zval).value.ht
Z_OBJVAL(zval)           (zval).value.obj
Z_OBJ_HANDLE(zval)       Z_OBJVAL(zval).handle
Z_OBJ_HT(zval)           Z_OBJVAL(zval).handlers
Z_RESVAL(zval)           (zval).value.lval

Z_TYPE_P(zval_p)         Z_TYPE(*zval_p)
Z_LVAL_P(zval_p)         Z_LVAL(*zval_p)
Z_BVAL_P(zval_p)         Z_BVAL(*zval_p)
Z_DVAL_P(zval_p)         Z_DVAL(*zval_p)
Z_STRVAL_P(zval_p)       Z_STRVAL(*zval_p)
Z_STRLEN_P(zval_p)       Z_STRLEN(*zval_p)
Z_ARRVAL_P(zval_p)       Z_ARRVAL(*zval_p)
Z_RESVAL_P(zval_p)       Z_RESVAL(*zval_p)
Z_OBJVAL_P(zval_p)       Z_OBJVAL(*zval_p)
Z_OBJ_HANDLE_P(zval_p)   Z_OBJ_HANDLE(*zval_p)
Z_OBJ_HT_P(zval_p)       Z_OBJ_HT(*zval_p)

http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.h#Z_LVAL
Exercise two: my_dump($val) (1/2)
●   Create a very simple my_dump($val) function:
●   my_dump(null); // null value!
●   my_dump(42); // Long: 42
●   my_dump(123.456); // Double: 123.456
●   my_dump(true); // Boolean: true
●   my_dump(“hello”); // String: hello
Exercise two: my_dump($val) (2/2)
●   Hints:
●   Define a pointer to a zval:
    zval *val;
●   Use “z” with zend_parse_parameters()
●   Switch/case based on the type of val
    (Z_TYPE_P(uservar))
●   Use php_printf() to print, except for strings from zval,
    since they may contain NULL characters:
    PHPWRITE(const char *, size_t);
Exercise two: solution
PHP_FUNCTION(my_dump) {
  zval *val;
  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", val) ==
FAILURE) {
    return;
  }
  switch (Z_TYPE_P(val)) {
    case IS_NULL:
      php_printf("NULL");
      break;
    case IS_BOOL:
      php_printf("Boolean: %s", Z_LVAL_P(val) ? "true" : "false");
      break;
    case IS_LONG:
      php_printf("Long: %ld", Z_LVAL_P(val));
      break;
    case IS_DOUBLE:
      php_printf("Double: %f", Z_DVAL_P(val));
      break;
    case IS_STRING:
      php_printf("String: ");
      PHPWRITE(Z_STRVAL_P(val), Z_STRLEN_P(val));
      break;
    default:
      php_printf("Not supported");
  }
}
PHP life cycles
●   4 functions (2 initializations, 2 shutdowns ones) let
    you do stuff at specific moments of the PHP life
    cycles:
    ●   PHP_MINIT_FUNCTION
    ●   PHP_MSHUTDOWN_FUNCTION
    ●   PHP_RINIT_FUNCTION
    ●   PHP_RSHUTDOWN_FUNCTION
PHP life cycles - CLI




●   Credits: Extending and Embedding PHP by Sara Golemon (2006 June 9th)
PHP life cycles – Web server
                     (prefork)




●   Credits: Extending and Embedding PHP by Sara Golemon (2006 June 9th)
PHP life cycles - Web server
                  (multi thread)




●   Credits: Extending and Embedding PHP by Sara Golemon (2006 June 9th)
Exercise three: MyClass (1/10)
●   Steps:
    ●   Create a class named “MyClass”
    ●   Create a class constant
    ●   Add some properties with various visibilities/modifiers
    ●   Add some methods
Exercise three: MyClass (2/10)
Exercise three: MyClass (3/10)




●   http://tinyurl.com/PHP-ext-MyClass-1
Exercise three: MyClass (4/10)
●   Declaring a class constant can be made from a C type:
    ●   zend_declare_class_constant_null();
    ●   zend_declare_class_constant_long();
    ●   zend_declare_class_constant_bool();
    ●   zend_declare_class_constant_double();
    ●   zend_declare_class_constant_stringl();
    ●   zend_declare_class_constant_string();
●   Or from a zval:
    ●   zend_declare_class_constant();
Exercise three: MyClass (5/10)




●   http://tinyurl.com/PHP-ext-MyClass-2
Exercise three: MyClass (6/10)
●   Creating class properties can be made from a C type:
    ●   zend_declare_property_long();
    ●   zend_declare_property_bool();
    ●   zend_declare_property_double();
    ●   zend_declare_property_stringl();
    ●   zend_declare_property_string();
●   Or from a zval:
    ●   zend_declare_property();
●   Visibility:
    ●   ZEND_ACC_PUBLIC, ZEND_ACC_PROTECTED, ZEND_ACC_PRIVATE
●   Modifiers:
    ●   ZEND_ACC_STATIC, ZEND_ACC_ABSTRACT, ZEND_ACC_FINAL
Exercise three: MyClass (7/10)




●   http://tinyurl.com/PHP-ext-MyClass-3
Exercise three: MyClass (8/10)
Exercise three: MyClass (9/10)
Exercise three: MyClass (10/10)




●   http://tinyurl.com/PHP-ext-MyClass-4
Questions?
Thanks
●   Don't forget to rate this workshop on https://joind.in/6386

Contenu connexe

Tendances

PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machinejulien pauli
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshopjulien pauli
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHPWim Godden
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension reviewjulien pauli
 
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
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpen Gurukul
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09Elizabeth Smith
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Pythonkwatch
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPGuilherme Blanco
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlHideaki Ohno
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Moriyoshi Koizumi
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021Ayesh Karunaratne
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesjulien pauli
 

Tendances (20)

PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
Php engine
Php enginePhp engine
Php engine
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension review
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
 
SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09SPL to the Rescue - Tek 09
SPL to the Rescue - Tek 09
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
 

En vedette

Desarrollo Profesional con PHP 2014/15 - Nivel Bajo / Medio
Desarrollo Profesional con PHP 2014/15 - Nivel Bajo / MedioDesarrollo Profesional con PHP 2014/15 - Nivel Bajo / Medio
Desarrollo Profesional con PHP 2014/15 - Nivel Bajo / MedioCarlos Buenosvinos
 
Certificacion Zend En Vivo Php Barcelona 2008
Certificacion Zend En Vivo Php Barcelona 2008Certificacion Zend En Vivo Php Barcelona 2008
Certificacion Zend En Vivo Php Barcelona 2008Carlos Buenosvinos
 
Php Introduction nikul
Php Introduction nikulPhp Introduction nikul
Php Introduction nikulNikul Shah
 
Internal php and gdb php core
Internal php and gdb php coreInternal php and gdb php core
Internal php and gdb php corealpha86
 
La métrique, ce n'est pas que pour le devops
La métrique, ce n'est pas que pour le devopsLa métrique, ce n'est pas que pour le devops
La métrique, ce n'est pas que pour le devopsPatrick Allaert
 
Maitriser les structures de données PHP 102 - Forum Paris 2012
Maitriser les structures de données PHP 102 - Forum Paris 2012Maitriser les structures de données PHP 102 - Forum Paris 2012
Maitriser les structures de données PHP 102 - Forum Paris 2012Patrick Allaert
 
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)Carlos Buenosvinos
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPCAnthony Ferrara
 
Masterizing PHP Data Structure 102 - PHPUK 2012
Masterizing PHP Data Structure 102 - PHPUK 2012Masterizing PHP Data Structure 102 - PHPUK 2012
Masterizing PHP Data Structure 102 - PHPUK 2012Patrick Allaert
 
Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Patrick Allaert
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPatrick Allaert
 
php and sapi and zendengine2 and...
php and sapi and zendengine2 and...php and sapi and zendengine2 and...
php and sapi and zendengine2 and...do_aki
 

En vedette (14)

Desarrollo Profesional con PHP 2014/15 - Nivel Bajo / Medio
Desarrollo Profesional con PHP 2014/15 - Nivel Bajo / MedioDesarrollo Profesional con PHP 2014/15 - Nivel Bajo / Medio
Desarrollo Profesional con PHP 2014/15 - Nivel Bajo / Medio
 
Certificacion Zend En Vivo Php Barcelona 2008
Certificacion Zend En Vivo Php Barcelona 2008Certificacion Zend En Vivo Php Barcelona 2008
Certificacion Zend En Vivo Php Barcelona 2008
 
Php Introduction nikul
Php Introduction nikulPhp Introduction nikul
Php Introduction nikul
 
Internal php and gdb php core
Internal php and gdb php coreInternal php and gdb php core
Internal php and gdb php core
 
Scrum, no eres tú, soy yo
Scrum, no eres tú, soy yoScrum, no eres tú, soy yo
Scrum, no eres tú, soy yo
 
La métrique, ce n'est pas que pour le devops
La métrique, ce n'est pas que pour le devopsLa métrique, ce n'est pas que pour le devops
La métrique, ce n'est pas que pour le devops
 
Maitriser les structures de données PHP 102 - Forum Paris 2012
Maitriser les structures de données PHP 102 - Forum Paris 2012Maitriser les structures de données PHP 102 - Forum Paris 2012
Maitriser les structures de données PHP 102 - Forum Paris 2012
 
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPC
 
Masterizing PHP Data Structure 102 - PHPUK 2012
Masterizing PHP Data Structure 102 - PHPUK 2012Masterizing PHP Data Structure 102 - PHPUK 2012
Masterizing PHP Data Structure 102 - PHPUK 2012
 
Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)Advanced debugging techniques (PHP)
Advanced debugging techniques (PHP)
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
 
php and sapi and zendengine2 and...
php and sapi and zendengine2 and...php and sapi and zendengine2 and...
php and sapi and zendengine2 and...
 
reveal.js 3.0.0
reveal.js 3.0.0reveal.js 3.0.0
reveal.js 3.0.0
 

Similaire à Create your own PHP extension, step by step - phpDay 2012 Verona

Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityGeorgePeterBanyard
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?Nick Belhomme
 
Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScriptJungsoo Nam
 
Unit 4
Unit 4Unit 4
Unit 4siddr
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java DevelopersYakov Fain
 
Extending php (7), the basics
Extending php (7), the basicsExtending php (7), the basics
Extending php (7), the basicsPierre Joye
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptKamil Toman
 
TLPI - 6 Process
TLPI - 6 ProcessTLPI - 6 Process
TLPI - 6 ProcessShu-Yu Fu
 
LLVM Backend Porting
LLVM Backend PortingLLVM Backend Porting
LLVM Backend PortingShiva Chen
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges✅ William Pinaud
 

Similaire à Create your own PHP extension, step by step - phpDay 2012 Verona (20)

Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?
 
PHP7 Presentation
PHP7 PresentationPHP7 Presentation
PHP7 Presentation
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScript
 
Unit 4
Unit 4Unit 4
Unit 4
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Extending php (7), the basics
Extending php (7), the basicsExtending php (7), the basics
Extending php (7), the basics
 
Experimental dtrace
Experimental dtraceExperimental dtrace
Experimental dtrace
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and Javascript
 
TLPI - 6 Process
TLPI - 6 ProcessTLPI - 6 Process
TLPI - 6 Process
 
Message in a bottle
Message in a bottleMessage in a bottle
Message in a bottle
 
LLVM Backend Porting
LLVM Backend PortingLLVM Backend Porting
LLVM Backend Porting
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 

Dernier

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 

Dernier (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 

Create your own PHP extension, step by step - phpDay 2012 Verona

  • 1. Create your own PHP extension, step by step Patrick Allaert, Derick Rethans, Rasmus Lerdorf phpDay 2012 Verona, Italy
  • 2. Patrick Allaert ● Founder of Libereco ● Playing with PHP/Linux for +10 years ● eZ Publish core developer ● Author of the APM PHP extension ● @patrick_allaert ● patrickallaert@php.net ● http://github.com/patrickallaert/ ● http://patrickallaert.blogspot.com/
  • 3. Derick Rethans ● Dutchman living in London ● PHP Engineer/Evangelist for 10gen (the MongoDB people), where I also work on the MongoDB PHP driver. ● Author of Xdebug ● Author of the mcrypt, input_filter, dbus, translit and date/time extensions
  • 4. Workshop overview ● Brief reminders about PHP architecture ● Configure your environment ● Grab the example extension ● Do some exercises while seeing a bit of theory
  • 6. Configuring your environment ● Debian-like: $ sudo apt-get install php5-dev
  • 7. Download the sample extension a) Using git: $ git clone git://github.com/patrickallaert/ PHP_Extension_Workshop.git b) Download archive at: https://github.com/patrickallaert/PHP_Extension_Wo rkshop/downloads
  • 8. Minimal C code (myext.c) #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_myext.h" zend_module_entry myext_module_entry = { STANDARD_MODULE_HEADER, "myext", NULL, /* Function entries */ NULL, /* Module init */ NULL, /* Module shutdown */ NULL, /* Request init */ NULL, /* Request shutdown */ NULL, /* Module information */ "0.1", /* Replace with version number for your extension */ STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_MYEXT ZEND_GET_MODULE(myext) #endif
  • 9. Compilation Prepare build environment: 1. $ phpize Configure the extension: 2. $ ./configure Compile it: 3. $ make Install it (may require root): 4. $ make install
  • 10. Verify installation $ php -d extension=myext.so -m You should see “myext” as part of the loaded extensions.
  • 11. Minimal config.m4 dnl config.m4 for myext PHP_ARG_ENABLE(myext, whether to enable myext support, [ --enable-myext Enable myext support]) if test "$PHP_MYEXT" != "no"; then PHP_NEW_EXTENSION(myext, myext.c, $ext_shared) fi
  • 12. Exercise one: fibonacci (1/7) ● F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1
  • 13. Exercise one: fibonacci (2/7) function fibo($n) { switch ($n) { case 0: case 1: return $n; } return fibo($n-2) + fibo($n-1); }
  • 18. Exercise one: fibonacci (7/7) Compile: $ make Install: $ make install Test: $ php -d extension=myext.so -r 'echo fibonacci(35), “n”;' 9227465
  • 19. Exercise one: fibonacci solution The full changes required to implement the fibonacci function are available at: http://tinyurl.com/PHP-ext-fibonacci
  • 20. zend_parse_parameters ● Handles the conversion of PHP userspace variables into C ones. ● Generate errors in the case of missing parameters or if the type is wrong.
  • 21. zend_parse_parameters ● Second parameter describes Type Cod Variable type e the type of the parameter(s) Boolean b zend_bool as a string composed of Long l long characters having all a Double d double special meaning. String s char *, int (length) Path p char *, int (length) ● To mark the start of optional Class C zend_class_entry* name parameter(s), a pipe (“|”) Resource r zval* character is used. Array a zval* Object o zval* zval z zval* Zval Z zval** pointer Callback f zend_fcall_info, zend_fcall_info_cache
  • 22. zend_parse_parameters examples ● sleep(), usleep(), func_get_arg(): zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &long) ● bin2hex(), quotemeta(), ord(), ucfirst(): zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) ● str*pos(): zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &haystack, &haystack_len, &needle, &offset) ● var_dump(): zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) ● file_put_contents() zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pz/| lr!", &filename, &filename_len, &data, &flags, &zcontext)
  • 23. OpenGrok (1/2) ● Your best friend to browse PHP's source code: http://lxr.php.net/
  • 25. zval (=== _zval_struct) struct _zval_struct { /* Variable information */ zvalue_value value; /* value */ zend_uint refcount__gc; zend_uchar type; /* active type */ zend_uchar is_ref__gc; }; typedef union _zvalue_value { long lval; /* long value */ double dval; /* double value */ struct { char *val; int len; } str; HashTable *ht; /* hash table value */ zend_object_value obj; } zvalue_value;
  • 26. Types ● IS_NULL ● IS_LONG ● IS_DOUBLE ● IS_BOOL ● IS_ARRAY ● IS_OBJECT ● IS_STRING ● IS_RESOURCE ● IS_CONSTANT ● IS_CONSTANT_ARRAY ● IS_CALLABLE ● http://lxr.php.net/xref/PHP_TRUNK/Zend/zend.h#IS_NULL
  • 27. Access macros Z_TYPE(zval) (zval).type Z_LVAL(zval) (zval).value.lval Z_BVAL(zval) ((zend_bool)(zval).value.lval) Z_DVAL(zval) (zval).value.dval Z_STRVAL(zval) (zval).value.str.val Z_STRLEN(zval) (zval).value.str.len Z_ARRVAL(zval) (zval).value.ht Z_OBJVAL(zval) (zval).value.obj Z_OBJ_HANDLE(zval) Z_OBJVAL(zval).handle Z_OBJ_HT(zval) Z_OBJVAL(zval).handlers Z_RESVAL(zval) (zval).value.lval Z_TYPE_P(zval_p) Z_TYPE(*zval_p) Z_LVAL_P(zval_p) Z_LVAL(*zval_p) Z_BVAL_P(zval_p) Z_BVAL(*zval_p) Z_DVAL_P(zval_p) Z_DVAL(*zval_p) Z_STRVAL_P(zval_p) Z_STRVAL(*zval_p) Z_STRLEN_P(zval_p) Z_STRLEN(*zval_p) Z_ARRVAL_P(zval_p) Z_ARRVAL(*zval_p) Z_RESVAL_P(zval_p) Z_RESVAL(*zval_p) Z_OBJVAL_P(zval_p) Z_OBJVAL(*zval_p) Z_OBJ_HANDLE_P(zval_p) Z_OBJ_HANDLE(*zval_p) Z_OBJ_HT_P(zval_p) Z_OBJ_HT(*zval_p) http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.h#Z_LVAL
  • 28. Exercise two: my_dump($val) (1/2) ● Create a very simple my_dump($val) function: ● my_dump(null); // null value! ● my_dump(42); // Long: 42 ● my_dump(123.456); // Double: 123.456 ● my_dump(true); // Boolean: true ● my_dump(“hello”); // String: hello
  • 29. Exercise two: my_dump($val) (2/2) ● Hints: ● Define a pointer to a zval: zval *val; ● Use “z” with zend_parse_parameters() ● Switch/case based on the type of val (Z_TYPE_P(uservar)) ● Use php_printf() to print, except for strings from zval, since they may contain NULL characters: PHPWRITE(const char *, size_t);
  • 30. Exercise two: solution PHP_FUNCTION(my_dump) { zval *val; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", val) == FAILURE) { return; } switch (Z_TYPE_P(val)) { case IS_NULL: php_printf("NULL"); break; case IS_BOOL: php_printf("Boolean: %s", Z_LVAL_P(val) ? "true" : "false"); break; case IS_LONG: php_printf("Long: %ld", Z_LVAL_P(val)); break; case IS_DOUBLE: php_printf("Double: %f", Z_DVAL_P(val)); break; case IS_STRING: php_printf("String: "); PHPWRITE(Z_STRVAL_P(val), Z_STRLEN_P(val)); break; default: php_printf("Not supported"); } }
  • 31. PHP life cycles ● 4 functions (2 initializations, 2 shutdowns ones) let you do stuff at specific moments of the PHP life cycles: ● PHP_MINIT_FUNCTION ● PHP_MSHUTDOWN_FUNCTION ● PHP_RINIT_FUNCTION ● PHP_RSHUTDOWN_FUNCTION
  • 32. PHP life cycles - CLI ● Credits: Extending and Embedding PHP by Sara Golemon (2006 June 9th)
  • 33. PHP life cycles – Web server (prefork) ● Credits: Extending and Embedding PHP by Sara Golemon (2006 June 9th)
  • 34. PHP life cycles - Web server (multi thread) ● Credits: Extending and Embedding PHP by Sara Golemon (2006 June 9th)
  • 35. Exercise three: MyClass (1/10) ● Steps: ● Create a class named “MyClass” ● Create a class constant ● Add some properties with various visibilities/modifiers ● Add some methods
  • 37. Exercise three: MyClass (3/10) ● http://tinyurl.com/PHP-ext-MyClass-1
  • 38. Exercise three: MyClass (4/10) ● Declaring a class constant can be made from a C type: ● zend_declare_class_constant_null(); ● zend_declare_class_constant_long(); ● zend_declare_class_constant_bool(); ● zend_declare_class_constant_double(); ● zend_declare_class_constant_stringl(); ● zend_declare_class_constant_string(); ● Or from a zval: ● zend_declare_class_constant();
  • 39. Exercise three: MyClass (5/10) ● http://tinyurl.com/PHP-ext-MyClass-2
  • 40. Exercise three: MyClass (6/10) ● Creating class properties can be made from a C type: ● zend_declare_property_long(); ● zend_declare_property_bool(); ● zend_declare_property_double(); ● zend_declare_property_stringl(); ● zend_declare_property_string(); ● Or from a zval: ● zend_declare_property(); ● Visibility: ● ZEND_ACC_PUBLIC, ZEND_ACC_PROTECTED, ZEND_ACC_PRIVATE ● Modifiers: ● ZEND_ACC_STATIC, ZEND_ACC_ABSTRACT, ZEND_ACC_FINAL
  • 41. Exercise three: MyClass (7/10) ● http://tinyurl.com/PHP-ext-MyClass-3
  • 44. Exercise three: MyClass (10/10) ● http://tinyurl.com/PHP-ext-MyClass-4
  • 46. Thanks ● Don't forget to rate this workshop on https://joind.in/6386